Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp =================================================================== --- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -43,6 +43,7 @@ #include #include #include +#include using namespace clang; using namespace ento; @@ -508,7 +509,23 @@ } } +static bool isBisonFile(ASTContext &C) { + const SourceManager &SM = C.getSourceManager(); + FileID FID = SM.getMainFileID(); + llvm::MemoryBuffer *Buffer = SM.getBuffer(FID); + const char *Start = Buffer->getBufferStart(); + if (strncmp(Start, "/* A Bison parser, made by", 26) == 0) + return true; + return false; +} + void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) { + if (isBisonFile(C)) { + if (Opts->AnalyzerDisplayProgress) + llvm::errs() << "Skipping bison-generated file\n"; + return; + } + // Don't run the actions if an error has occurred with parsing the file. DiagnosticsEngine &Diags = PP.getDiagnostics(); if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred()) Index: test/Analysis/yaccignore.c =================================================================== --- /dev/null +++ test/Analysis/yaccignore.c @@ -0,0 +1,9 @@ +/* A Bison parser, made by GNU Bison 1.875. */ + +// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s + +// expected-no-diagnostics +int foo() { + int *x = 0; + return *x; // no-warning +}