|
35 | 35 | #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
36 | 36 | #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
37 | 37 | #include "llvm/ADT/PostOrderIterator.h"
|
| 38 | +#include "llvm/ADT/ScopeExit.h" |
38 | 39 | #include "llvm/ADT/Statistic.h"
|
39 | 40 | #include "llvm/Support/FileSystem.h"
|
40 | 41 | #include "llvm/Support/Path.h"
|
@@ -493,13 +494,11 @@ void AnalysisConsumer::HandleDeclsCallGraph(const unsigned LocalTUDeclsSize) {
|
493 | 494 | }
|
494 | 495 | }
|
495 | 496 |
|
496 |
| -static bool isBisonFile(ASTContext &C) { |
| 497 | +static bool fileContainsString(StringRef Substring, ASTContext &C) { |
497 | 498 | const SourceManager &SM = C.getSourceManager();
|
498 | 499 | FileID FID = SM.getMainFileID();
|
499 | 500 | StringRef Buffer = SM.getBufferOrFake(FID).getBuffer();
|
500 |
| - if (Buffer.startswith("/* A Bison parser, made by")) |
501 |
| - return true; |
502 |
| - return false; |
| 501 | + return Buffer.contains(Substring); |
503 | 502 | }
|
504 | 503 |
|
505 | 504 | void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
|
@@ -546,38 +545,48 @@ void AnalysisConsumer::reportAnalyzerProgress(StringRef S) {
|
546 | 545 | }
|
547 | 546 |
|
548 | 547 | void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
|
549 |
| - |
550 | 548 | // Don't run the actions if an error has occurred with parsing the file.
|
551 | 549 | DiagnosticsEngine &Diags = PP.getDiagnostics();
|
552 | 550 | if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
|
553 | 551 | return;
|
554 | 552 |
|
555 |
| - if (isBisonFile(C)) { |
| 553 | + // Explicitly destroy the PathDiagnosticConsumer. This will flush its output. |
| 554 | + // FIXME: This should be replaced with something that doesn't rely on |
| 555 | + // side-effects in PathDiagnosticConsumer's destructor. This is required when |
| 556 | + // used with option -disable-free. |
| 557 | + const auto DiagFlusherScopeExit = |
| 558 | + llvm::make_scope_exit([this] { Mgr.reset(); }); |
| 559 | + |
| 560 | + if (Opts->ShouldIgnoreBisonGeneratedFiles && |
| 561 | + fileContainsString("/* A Bison parser, made by", C)) { |
556 | 562 | reportAnalyzerProgress("Skipping bison-generated file\n");
|
557 |
| - } else if (Opts->DisableAllCheckers) { |
| 563 | + return; |
| 564 | + } |
558 | 565 |
|
559 |
| - // Don't analyze if the user explicitly asked for no checks to be performed |
560 |
| - // on this file. |
| 566 | + if (Opts->ShouldIgnoreFlexGeneratedFiles && |
| 567 | + fileContainsString("/* A lexical scanner generated by flex", C)) { |
| 568 | + reportAnalyzerProgress("Skipping flex-generated file\n"); |
| 569 | + return; |
| 570 | + } |
| 571 | + |
| 572 | + // Don't analyze if the user explicitly asked for no checks to be performed |
| 573 | + // on this file. |
| 574 | + if (Opts->DisableAllCheckers) { |
561 | 575 | reportAnalyzerProgress("All checks are disabled using a supplied option\n");
|
562 |
| - } else { |
563 |
| - // Otherwise, just run the analysis. |
564 |
| - runAnalysisOnTranslationUnit(C); |
| 576 | + return; |
565 | 577 | }
|
566 | 578 |
|
| 579 | + // Otherwise, just run the analysis. |
| 580 | + runAnalysisOnTranslationUnit(C); |
| 581 | + |
567 | 582 | // Count how many basic blocks we have not covered.
|
568 | 583 | NumBlocksInAnalyzedFunctions = FunctionSummaries.getTotalNumBasicBlocks();
|
569 | 584 | NumVisitedBlocksInAnalyzedFunctions =
|
570 | 585 | FunctionSummaries.getTotalNumVisitedBasicBlocks();
|
571 | 586 | if (NumBlocksInAnalyzedFunctions > 0)
|
572 | 587 | PercentReachableBlocks =
|
573 |
| - (FunctionSummaries.getTotalNumVisitedBasicBlocks() * 100) / |
| 588 | + (FunctionSummaries.getTotalNumVisitedBasicBlocks() * 100) / |
574 | 589 | NumBlocksInAnalyzedFunctions;
|
575 |
| - |
576 |
| - // Explicitly destroy the PathDiagnosticConsumer. This will flush its output. |
577 |
| - // FIXME: This should be replaced with something that doesn't rely on |
578 |
| - // side-effects in PathDiagnosticConsumer's destructor. This is required when |
579 |
| - // used with option -disable-free. |
580 |
| - Mgr.reset(); |
581 | 590 | }
|
582 | 591 |
|
583 | 592 | AnalysisConsumer::AnalysisMode
|
|
0 commit comments