Skip to content

Commit 69a0ff4

Browse files
committed
gcc-parser: tag trace events produced by clang --analyze
1 parent 685c672 commit 69a0ff4

File tree

3 files changed

+142
-124
lines changed

3 files changed

+142
-124
lines changed

src/gcc-parser.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ struct GccPostProcessor::Private {
559559

560560
void transGccAnal(Defect *pDef) const;
561561
void polishGccAnal(Defect *pDef) const;
562+
void polishClangAnal(Defect *pDef) const;
562563
void transSuffixGeneric(Defect *pDef, const std::string, const RE &) const;
563564
void transShellCheckId(Defect *pDef) const;
564565

@@ -624,6 +625,22 @@ void GccPostProcessor::Private::polishGccAnal(Defect *pDef) const
624625
}
625626
}
626627

628+
void GccPostProcessor::Private::polishClangAnal(Defect *pDef) const
629+
{
630+
if ("CLANG_WARNING" != pDef->checker)
631+
return;
632+
633+
// FIXME: we should distinguish `clang --analyze` and clang compiler
634+
635+
for (DefEvent &evt : pDef->events) {
636+
if (evt.verbosityLevel != /* note */ 1 || evt.event != "note")
637+
// not a "note" event
638+
continue;
639+
640+
evt.verbosityLevel = /* trace */ 2;
641+
}
642+
}
643+
627644
void GccPostProcessor::Private::transSuffixGeneric(
628645
Defect *pDef,
629646
const std::string checker,
@@ -653,6 +670,7 @@ void GccPostProcessor::apply(Defect *pDef) const
653670
d->transSuffixGeneric(pDef, "SHELLCHECK_WARNING", d->reShellCheckId);
654671

655672
d->polishGccAnal(pDef);
673+
d->polishClangAnal(pDef);
656674

657675
d->langDetector.inferLangFromChecker(pDef);
658676
}

tests/csgrep/63-gcc-parser-checker-lang-stdout.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
"column": 3,
322322
"event": "note",
323323
"message": "expanded from macro 'fprintf'",
324-
"verbosity_level": "1"
324+
"verbosity_level": "2"
325325
},
326326
{
327327
"file_name": "",
@@ -343,7 +343,7 @@
343343
"column": 8,
344344
"event": "note",
345345
"message": "Memory is allocated",
346-
"verbosity_level": "1"
346+
"verbosity_level": "2"
347347
},
348348
{
349349
"file_name": "",
@@ -365,7 +365,7 @@
365365
"column": 6,
366366
"event": "note",
367367
"message": "Assuming 'buf' is not equal to NULL",
368-
"verbosity_level": "1"
368+
"verbosity_level": "2"
369369
},
370370
{
371371
"file_name": "",
@@ -387,7 +387,7 @@
387387
"column": 2,
388388
"event": "note",
389389
"message": "Taking false branch",
390-
"verbosity_level": "1"
390+
"verbosity_level": "2"
391391
},
392392
{
393393
"file_name": "",
@@ -409,7 +409,7 @@
409409
"column": 9,
410410
"event": "note",
411411
"message": "Assuming the condition is false",
412-
"verbosity_level": "1"
412+
"verbosity_level": "2"
413413
},
414414
{
415415
"file_name": "",
@@ -431,7 +431,7 @@
431431
"column": 2,
432432
"event": "note",
433433
"message": "Loop condition is false. Execution continues on line 65",
434-
"verbosity_level": "1"
434+
"verbosity_level": "2"
435435
},
436436
{
437437
"file_name": "",
@@ -453,7 +453,7 @@
453453
"column": 6,
454454
"event": "note",
455455
"message": "Assuming 'optind' is not equal to 'argc'",
456-
"verbosity_level": "1"
456+
"verbosity_level": "2"
457457
},
458458
{
459459
"file_name": "",
@@ -475,7 +475,7 @@
475475
"column": 2,
476476
"event": "note",
477477
"message": "Taking false branch",
478-
"verbosity_level": "1"
478+
"verbosity_level": "2"
479479
},
480480
{
481481
"file_name": "",
@@ -497,7 +497,7 @@
497497
"column": 9,
498498
"event": "note",
499499
"message": "Assuming 'optind' is < 'argc'",
500-
"verbosity_level": "1"
500+
"verbosity_level": "2"
501501
},
502502
{
503503
"file_name": "",
@@ -519,7 +519,7 @@
519519
"column": 2,
520520
"event": "note",
521521
"message": "Loop condition is true. Entering loop body",
522-
"verbosity_level": "1"
522+
"verbosity_level": "2"
523523
},
524524
{
525525
"file_name": "",
@@ -541,7 +541,7 @@
541541
"column": 7,
542542
"event": "note",
543543
"message": "Assuming the condition is true",
544-
"verbosity_level": "1"
544+
"verbosity_level": "2"
545545
},
546546
{
547547
"file_name": "",
@@ -563,7 +563,7 @@
563563
"column": 3,
564564
"event": "note",
565565
"message": "Taking true branch",
566-
"verbosity_level": "1"
566+
"verbosity_level": "2"
567567
},
568568
{
569569
"file_name": "",
@@ -585,7 +585,7 @@
585585
"column": 4,
586586
"event": "note",
587587
"message": "Potential leak of memory pointed to by 'buf'",
588-
"verbosity_level": "1"
588+
"verbosity_level": "2"
589589
},
590590
{
591591
"file_name": "",
@@ -607,7 +607,7 @@
607607
"column": 3,
608608
"event": "note",
609609
"message": "expanded from macro 'fprintf'",
610-
"verbosity_level": "1"
610+
"verbosity_level": "2"
611611
},
612612
{
613613
"file_name": "",

0 commit comments

Comments
 (0)