-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] Prevent misuses of -analyze-function
Sometimes when I pass the mentioned option I forget about passing the parameter list for c++ sources. It would be also useful newcomers to learn about this. This patch introduces some logic checking common misuses involving `-analyze-function`. Reviewed-By: martong Differential Revision: https://reviews.llvm.org/D118690
- Loading branch information
Balazs Benics
committed
Feb 8, 2022
1 parent
f2c99ea
commit 841817b
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
// 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. | ||
|
||
@interface MyClass | ||
- (int)messageWithFoo:(int)foo bar:(int)bar; | ||
@end | ||
|
||
@implementation MyClass | ||
- (int)messageWithFoo:(int)foo bar:(int)bar { | ||
return foo + bar; | ||
} | ||
@end |