Skip to content

Commit 34d3324

Browse files
committed
Resolve the function decl from a function pointer
1 parent 99e07ce commit 34d3324

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

clang/lib/StaticAnalyzer/Checkers/ThreadModeling.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
88
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
99

10-
#include <clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h>
10+
#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
1111

1212
using namespace clang;
1313
using namespace ento;
1414

15+
#pragma clang optimize off
16+
1517
namespace {
1618

1719
// Since we are looking to extract the arguments, go with pre call for now
1820
class ThreadModeling : public Checker<check::PreCall> {
1921

20-
constexpr static CallDescriptionSet ThreadCreateCalls {
22+
const CallDescriptionSet ThreadCreateCalls {
2123
{ CDM::CLibrary, {"pthread_create"}, 4},
2224
};
2325

@@ -45,13 +47,22 @@ void ThreadModeling::checkPreCall(const CallEvent &Call, CheckerContext &C) cons
4547
void *restrict arg);
4648
*/
4749
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);
4951
assert(StartRoutineExpr && "start_routine should exist"); // XXX: might fail if in diff TU?
5052

5153
// 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");
5365

54-
// 4. Resolve FunctionDecl
5566
// 5. Get AST (single TU for now)
5667
// 6. Resolve AST to Call
5768
// 7. Inline Call

0 commit comments

Comments
 (0)