Skip to content

Commit 6554b46

Browse files
kvbridgerseinvbri
andauthored
Add option for pthread modeling, default false. Update LITs (#4)
Add option for pthread modeling set to a default of false. Uses must opt-in. Update LITs so all pass. Co-authored-by: einvbri <[email protected]>
1 parent 53b4d5d commit 6554b46

12 files changed

+18
-8
lines changed

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ ANALYZER_OPTION(bool, MayInlineCXXStandardLibrary, "c++-stdlib-inlining",
127127
"considered for inlining.",
128128
true)
129129

130+
ANALYZER_OPTION(bool, ModelPthreads, "model-pthreads",
131+
"Model Pthreads if enabled - default is disabled ",
132+
false
133+
)
134+
130135
ANALYZER_OPTION(bool, MayInlineCXXAllocator, "c++-allocator-inlining",
131136
"Whether or not allocator and deallocator calls may be "
132137
"considered for inlining.",

clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ static bool isTrivialObjectAssignment(const CallEvent &Call) {
12961296
void ExprEngine::defaultEvalCall(NodeBuilder &Bldr, ExplodedNode *Pred,
12971297
const CallEvent &CallTemplate,
12981298
const EvalCallOptions &CallOpts) {
1299+
AnalyzerOptions &Opts = AMgr.getAnalyzerOptions();
12991300
// Make sure we have the most recent state attached to the call.
13001301
ProgramStateRef State = Pred->getState();
13011302
CallEventRef<> Call = CallTemplate.cloneWithState(State);
@@ -1322,7 +1323,7 @@ void ExprEngine::defaultEvalCall(NodeBuilder &Bldr, ExplodedNode *Pred,
13221323

13231324
// TODO: make this a proper mode
13241325
// Special case thread creation
1325-
if (isThread(*Call)) {
1326+
if (isThread(*Call) && Opts.ModelPthreads) {
13261327
llvm::errs() << "Hijacking pthread_create(3)\n";
13271328
threadBifurcate(*Call, D, Bldr, Pred, State);
13281329
return;

clang/test/Analysis/SD-tests/thread-modeling-inline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
2-
// RUN: -analyzer-checker=debug.ExprInspection
2+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
33

44
#define NULL ((void*) 0)
55
enum bool {

clang/test/Analysis/SD-tests/thread-modeling-inline2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
2-
// RUN: -analyzer-checker=debug.ExprInspection
2+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
33

44
#define NULL ((void*) 0)
55
enum bool {

clang/test/Analysis/SD-tests/thread-modeling-leak.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
22
// RUN: -analyzer-checker=core \
33
// RUN: -analyzer-checker=unix \
4-
// RUN: -analyzer-checker=debug.ExprInspection
4+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
55

66
#define NULL ((void*) 0)
77

clang/test/Analysis/SD-tests/thread-modeling-leak2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
22
// RUN: -analyzer-checker=core \
33
// RUN: -analyzer-checker=unix \
4-
// RUN: -analyzer-checker=debug.ExprInspection
4+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
55

66
#define NULL ((void*) 0)
77

clang/test/Analysis/SD-tests/thread-modeling-null-deref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
22
// RUN: -analyzer-checker=core \
3-
// RUN: -analyzer-checker=debug.ExprInspection
3+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
44

55
#define NULL ((void*) 0)
66
enum bool {

clang/test/Analysis/SD-tests/thread-modeling-null-deref2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
22
// RUN: -analyzer-checker=core \
3-
// RUN: -analyzer-checker=debug.ExprInspection
3+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
44

55
#define NULL ((void*) 0)
66
enum bool {

clang/test/Analysis/SD-tests/thread-modeling-path-dependent-leak.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_analyze_cc1 -Wno-strict-prototypes -Wno-error=implicit-int -verify %s \
22
// RUN: -analyzer-checker=core \
33
// RUN: -analyzer-checker=unix \
4-
// RUN: -analyzer-checker=debug.ExprInspection
4+
// RUN: -analyzer-checker=debug.ExprInspection -analyzer-config model-pthreads=true
55

66
#define NULL ((void*) 0)
77

clang/test/Analysis/analyzer-config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
// CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
100100
// CHECK-NEXT: mode = deep
101101
// CHECK-NEXT: model-path = ""
102+
// CHECK-NEXT: model-pthreads = false
102103
// CHECK-NEXT: notes-as-events = false
103104
// CHECK-NEXT: nullability:NoDiagnoseCallsToSystemHeaders = false
104105
// CHECK-NEXT: objc-inlining = true
@@ -126,6 +127,7 @@
126127
// CHECK-NEXT: suppress-c++-stdlib = true
127128
// CHECK-NEXT: suppress-inlined-defensive-checks = true
128129
// CHECK-NEXT: suppress-null-return-paths = true
130+
// CHECK-NEXT: thread-aware = true
129131
// CHECK-NEXT: track-conditions = true
130132
// CHECK-NEXT: track-conditions-debug = false
131133
// CHECK-NEXT: unix.DynamicMemoryModeling:AddNoOwnershipChangeNotes = true

0 commit comments

Comments
 (0)