Skip to content

Commit 59118dd

Browse files
committed
Add method if a call is to create a thread
1 parent 39608fc commit 59118dd

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class ExprEngine {
137137
private:
138138
cross_tu::CrossTranslationUnitContext &CTU;
139139
bool IsCTUEnabled;
140+
bool IsThreadEnabled;
140141

141142
AnalysisManager &AMgr;
142143

@@ -807,6 +808,9 @@ class ExprEngine {
807808
const ExplodedNode *Pred,
808809
const EvalCallOptions &CallOpts = {});
809810

811+
/// Check if this is a call to create a thread
812+
bool isThread(CallEvent const &Call) const;
813+
810814
/// Checks whether our policies allow us to inline a non-POD type array
811815
/// construction.
812816
bool shouldInlineArrayConstruction(const ProgramStateRef State,

clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Support/Casting.h"
2626
#include "llvm/Support/Compiler.h"
2727
#include "llvm/Support/SaveAndRestore.h"
28+
#include <clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h>
2829
#include <optional>
2930

3031
using namespace clang;
@@ -1144,6 +1145,14 @@ bool ExprEngine::shouldInlineCall(const CallEvent &Call, const Decl *D,
11441145
return true;
11451146
}
11461147

1148+
static const CallDescriptionSet ThreadCreateCalls {
1149+
{ CDM::CLibrary, {"pthread_create"}, 4},
1150+
};
1151+
1152+
bool ExprEngine::isThread(CallEvent const &Call) const {
1153+
return ThreadCreateCalls.contains(Call);
1154+
}
1155+
11471156
bool ExprEngine::shouldInlineArrayConstruction(const ProgramStateRef State,
11481157
const CXXConstructExpr *CE,
11491158
const LocationContext *LCtx) {
@@ -1241,6 +1250,8 @@ void ExprEngine::defaultEvalCall(NodeBuilder &Bldr, ExplodedNode *Pred,
12411250
RuntimeDefinition RD = Call->getRuntimeDefinition();
12421251
Call->setForeign(RD.isForeign());
12431252
const Decl *D = RD.getDecl();
1253+
1254+
12441255
if (shouldInlineCall(*Call, D, Pred, CallOpts)) {
12451256
if (RD.mayHaveOtherDefinitions()) {
12461257
AnalyzerOptions &Options = getAnalysisManager().options;

0 commit comments

Comments
 (0)