aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
diff options
context:
space:
mode:
authorBalazs Benics <balazs.benics@sigmatechnology.se>2022-02-16 10:33:21 +0100
committerBalazs Benics <balazs.benics@sigmatechnology.se>2022-02-16 10:33:21 +0100
commitb3c0014e5a7530645f502d8b19ef1df313cc85b9 (patch)
treed616a6716738c9677ecb53d9141621ff0e68f031 /clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
parent69a7d49de6a0368c0ba1aec4d8e2ced11c705c2f (diff)
downloadllvm-b3c0014e5a7530645f502d8b19ef1df313cc85b9.zip
llvm-b3c0014e5a7530645f502d8b19ef1df313cc85b9.tar.gz
llvm-b3c0014e5a7530645f502d8b19ef1df313cc85b9.tar.bz2
Revert "Revert "[analyzer] Prevent misuses of -analyze-function""
This reverts commit 620d99b7edc64ee87b1ce209f179305e6a919006. Let's see if removing the two offending RUN lines makes this patch pass. Not ideal to drop tests but, it's just a debugging feature, probably not that important.
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 323c002..9e96e00 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -499,6 +499,28 @@ static bool fileContainsString(StringRef Substring, ASTContext &C) {
return Buffer.contains(Substring);
}
+static void reportAnalyzerFunctionMisuse(const AnalyzerOptions &Opts,
+ const ASTContext &Ctx) {
+ llvm::errs() << "Every top-level function was skipped.\n";
+
+ if (!Opts.AnalyzerDisplayProgress)
+ llvm::errs() << "Pass the -analyzer-display-progress for tracking which "
+ "functions are analyzed.\n";
+
+ bool HasBrackets =
+ Opts.AnalyzeSpecificFunction.find("(") != std::string::npos;
+
+ if (Ctx.getLangOpts().CPlusPlus && !HasBrackets) {
+ llvm::errs()
+ << "For analyzing C++ code you need to pass the function parameter "
+ "list: -analyze-function=\"foobar(int, _Bool)\"\n";
+ } else if (!Ctx.getLangOpts().CPlusPlus && HasBrackets) {
+ llvm::errs() << "For analyzing C code you shouldn't pass the function "
+ "parameter list, only the name of the function: "
+ "-analyze-function=foobar\n";
+ }
+}
+
void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
BugReporter BR(*Mgr);
TranslationUnitDecl *TU = C.getTranslationUnitDecl();
@@ -535,6 +557,14 @@ void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
BR.FlushReports();
RecVisitorBR = nullptr;
+
+ // If the user wanted to analyze a specific function and the number of basic
+ // blocks analyzed is zero, than the user might not specified the function
+ // name correctly.
+ // FIXME: The user might have analyzed the requested function in Syntax mode,
+ // but we are unaware of that.
+ if (!Opts->AnalyzeSpecificFunction.empty() && NumFunctionsAnalyzed == 0)
+ reportAnalyzerFunctionMisuse(*Opts, *Ctx);
}
void AnalysisConsumer::reportAnalyzerProgress(StringRef S) {