[clang] 620d99b - Revert "[analyzer] Prevent misuses of -analyze-function"

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 8 08:43:33 PST 2022


Author: Balazs Benics
Date: 2022-02-08T17:42:46+01:00
New Revision: 620d99b7edc64ee87b1ce209f179305e6a919006

URL: https://github.com/llvm/llvm-project/commit/620d99b7edc64ee87b1ce209f179305e6a919006
DIFF: https://github.com/llvm/llvm-project/commit/620d99b7edc64ee87b1ce209f179305e6a919006.diff

LOG: Revert "[analyzer] Prevent misuses of -analyze-function"

This reverts commit 841817b1ed26c1fbb709957d54c0e2751624fbf8.

Ah, it still fails on build bots for some reason.
Pinning the target triple was not enough.

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 
    clang/test/Analysis/analyze-function-guide.cpp
    clang/test/Analysis/analyze-function-guide.m


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 9e96e00011f4f..323c002d0cef6 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -499,28 +499,6 @@ 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();
@@ -557,14 +535,6 @@ 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) {

diff  --git a/clang/test/Analysis/analyze-function-guide.cpp b/clang/test/Analysis/analyze-function-guide.cpp
deleted file mode 100644
index 4e773630a259d..0000000000000
--- a/clang/test/Analysis/analyze-function-guide.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-int fizzbuzz(int x, bool y) {
-  return x + y;
-}
-
-// C++ but not uses parentheses in the '-analyze-function' option.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='missing_fn' -x c++ \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-CXX
-//
-// CHECK-CXX:      Every top-level function was skipped.
-// CHECK-CXX-NEXT: Pass the -analyzer-display-progress for tracking which functions are analyzed.
-// CHECK-CXX-NEXT: For analyzing C++ code you need to pass the function parameter list: -analyze-function="foobar(int, _Bool)"
-
-// C but uses parentheses in the '-analyze-function' option.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='missing_fn()' -x c -Dbool=_Bool \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-C
-//
-// CHECK-C:      Every top-level function was skipped.
-// CHECK-C-NEXT: Pass the -analyzer-display-progress for tracking which functions are analyzed.
-// CHECK-C-NEXT: For analyzing C code you shouldn't pass the function parameter list, only the name of the function: -analyze-function=foobar
-
-// The user passed the '-analyzer-display-progress' option, we don't need to advocate it.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function=missing_fn \
-// RUN:   -analyzer-display-progress -x c -Dbool=_Bool \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-DONT-ADVOCATE-DISPLAY-PROGRESS
-//
-// CHECK-DONT-ADVOCATE-DISPLAY-PROGRESS:     Every top-level function was skipped.
-// CHECK-DONT-ADVOCATE-DISPLAY-PROGRESS-NOT: Pass the -analyzer-display-progress
-
-// The user passed the '-analyze-function' option but that doesn't mach to any declaration.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='missing_fn()' -x c++ \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-ADVOCATE-DISPLAY-PROGRESS
-//
-// CHECK-ADVOCATE-DISPLAY-PROGRESS:      Every top-level function was skipped.
-// CHECK-ADVOCATE-DISPLAY-PROGRESS-NEXT: Pass the -analyzer-display-progress for tracking which functions are analyzed.
-// CHECK-ADVOCATE-DISPLAY-PROGRESS-NOT:  For analyzing
-
-// The user passed the '-analyze-function' option and that matches on a
-// declaration in C++ mode.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='fizzbuzz(int, _Bool)' -x c++ \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-EMPTY --allow-empty
-//
-// Expected empty standard output.
-// CHECK-EMPTY-NOT: Every top-level function was skipped.
-
-// The user passed the '-analyze-function' option and that matches on a
-// declaration in C mode.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='fizzbuzz' -x c -Dbool=_Bool \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-EMPTY2 --allow-empty
-//
-// Expected empty standard output.
-// CHECK-EMPTY2-NOT: Every top-level function was skipped.
-
-// Same as the previous but syntax mode only.
-// FIXME: This should have empty standard output.
-//
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config ipa=none \
-// RUN:   -analyze-function='fizzbuzz(int, _Bool)' -x c++ \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-EMPTY3 --allow-empty
-//
-// FIXME: This should have empty standard output.
-// CHECK-EMPTY3:      Every top-level function was skipped.
-// CHECK-EMPTY3-NEXT: Pass the -analyzer-display-progress for tracking which functions are analyzed.

diff  --git a/clang/test/Analysis/analyze-function-guide.m b/clang/test/Analysis/analyze-function-guide.m
deleted file mode 100644
index fa79cd0dd3c3f..0000000000000
--- a/clang/test/Analysis/analyze-function-guide.m
+++ /dev/null
@@ -1,26 +0,0 @@
-
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='-[MyClass messageWithFoo:bar:]' \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-MATCH --allow-empty
-//
-// Expected empty standard output.
-// CHECK-MATCH-NOT: Every top-level function was skipped.
-
-// RUN: %clang_analyze_cc1 -analyzer-checker=core \
-// RUN:   -analyze-function='missing_fn' \
-// RUN:   -triple x86_64-pc-linux-gnu 2>&1 %s \
-// RUN: | FileCheck %s -check-prefix=CHECK-MISSING
-//
-// CHECK-MISSING: Every top-level function was skipped.
-// CHECK-MISSING: Pass the -analyzer-display-progress for tracking which functions are analyzed.
-
- at interface MyClass
-- (int)messageWithFoo:(int)foo bar:(int)bar;
- at end
-
- at implementation MyClass
-- (int)messageWithFoo:(int)foo bar:(int)bar {
-  return foo + bar;
-}
- at end


        


More information about the cfe-commits mailing list