|
7 | 7 | #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" |
8 | 8 | #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" |
9 | 9 |
|
10 | | -#include <clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h> |
| 10 | +#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h" |
11 | 11 |
|
12 | 12 | using namespace clang; |
13 | 13 | using namespace ento; |
14 | 14 |
|
| 15 | +#pragma clang optimize off |
| 16 | + |
15 | 17 | namespace { |
16 | 18 |
|
17 | 19 | // Since we are looking to extract the arguments, go with pre call for now |
18 | 20 | class ThreadModeling : public Checker<check::PreCall> { |
19 | 21 |
|
20 | | - constexpr static CallDescriptionSet ThreadCreateCalls { |
| 22 | + const CallDescriptionSet ThreadCreateCalls { |
21 | 23 | { CDM::CLibrary, {"pthread_create"}, 4}, |
22 | 24 | }; |
23 | 25 |
|
@@ -45,13 +47,22 @@ void ThreadModeling::checkPreCall(const CallEvent &Call, CheckerContext &C) cons |
45 | 47 | void *restrict arg); |
46 | 48 | */ |
47 | 49 | assert(Call.getNumArgs() == 4 && "pthread_create(3) should have 4 arguments"); |
48 | | - const Expr *StartRoutineExpr = Call.getArgExpr(2); |
| 50 | + Expr const *StartRoutineExpr = Call.getArgExpr(2); |
49 | 51 | assert(StartRoutineExpr && "start_routine should exist"); // XXX: might fail if in diff TU? |
50 | 52 |
|
51 | 53 | // 3. Get the function pointer for `start_routine` |
52 | | - const SVal SRV = C.getSVal(StartRoutineExpr); |
| 54 | + SVal const SRV = C.getSVal(StartRoutineExpr); |
| 55 | + MemRegion const *SRR = SRV.getAsRegion(); |
| 56 | + assert(SRR && "start_routine should be a pointer"); |
| 57 | + |
| 58 | + // 4. Resolve FunctionDecl from pointer |
| 59 | + FunctionDecl const *StartRoutine = nullptr; |
| 60 | + |
| 61 | + if (auto const *FR = dyn_cast<FunctionCodeRegion>(SRR)) { |
| 62 | + StartRoutine = dyn_cast<FunctionDecl>(FR->getDecl()); |
| 63 | + } // XXX: Can the function pointer be a different region type? (e.g. SymbolicRegion) |
| 64 | + assert(StartRoutine && "start_routine be a valid function pointer"); |
53 | 65 |
|
54 | | - // 4. Resolve FunctionDecl |
55 | 66 | // 5. Get AST (single TU for now) |
56 | 67 | // 6. Resolve AST to Call |
57 | 68 | // 7. Inline Call |
|
0 commit comments