ThreadSafetyCommon.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. //===- ThreadSafetyCommon.cpp ----------------------------------*- C++ --*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Implementation of the interfaces declared in ThreadSafetyCommon.h
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Analysis/Analyses/ThreadSafetyCommon.h"
  14. #include "clang/AST/Attr.h"
  15. #include "clang/AST/DeclCXX.h"
  16. #include "clang/AST/ExprCXX.h"
  17. #include "clang/AST/StmtCXX.h"
  18. #include "clang/Analysis/Analyses/PostOrderCFGView.h"
  19. #include "clang/Analysis/Analyses/ThreadSafetyTIL.h"
  20. #include "clang/Analysis/Analyses/ThreadSafetyTraverse.h"
  21. #include "clang/Analysis/AnalysisContext.h"
  22. #include "clang/Analysis/CFG.h"
  23. #include "clang/Basic/OperatorKinds.h"
  24. #include "clang/Basic/SourceLocation.h"
  25. #include "clang/Basic/SourceManager.h"
  26. #include "llvm/ADT/DenseMap.h"
  27. #include "llvm/ADT/SmallVector.h"
  28. #include "llvm/ADT/StringRef.h"
  29. #include <algorithm>
  30. #include <climits>
  31. #include <vector>
  32. namespace clang {
  33. namespace threadSafety {
  34. typedef SExprBuilder::CallingContext CallingContext;
  35. til::SExpr *SExprBuilder::lookupStmt(const Stmt *S) {
  36. auto It = SMap.find(S);
  37. if (It != SMap.end())
  38. return It->second;
  39. return nullptr;
  40. }
  41. void SExprBuilder::insertStmt(const Stmt *S, til::Variable *V) {
  42. SMap.insert(std::make_pair(S, V));
  43. }
  44. til::SCFG *SExprBuilder::buildCFG(CFGWalker &Walker) {
  45. Walker.walk(*this);
  46. return Scfg;
  47. }
  48. // Translate a clang statement or expression to a TIL expression.
  49. // Also performs substitution of variables; Ctx provides the context.
  50. // Dispatches on the type of S.
  51. til::SExpr *SExprBuilder::translate(const Stmt *S, CallingContext *Ctx) {
  52. if (!S)
  53. return nullptr;
  54. // Check if S has already been translated and cached.
  55. // This handles the lookup of SSA names for DeclRefExprs here.
  56. if (til::SExpr *E = lookupStmt(S))
  57. return E;
  58. switch (S->getStmtClass()) {
  59. case Stmt::DeclRefExprClass:
  60. return translateDeclRefExpr(cast<DeclRefExpr>(S), Ctx);
  61. case Stmt::CXXThisExprClass:
  62. return translateCXXThisExpr(cast<CXXThisExpr>(S), Ctx);
  63. case Stmt::MemberExprClass:
  64. return translateMemberExpr(cast<MemberExpr>(S), Ctx);
  65. case Stmt::CallExprClass:
  66. return translateCallExpr(cast<CallExpr>(S), Ctx);
  67. case Stmt::CXXMemberCallExprClass:
  68. return translateCXXMemberCallExpr(cast<CXXMemberCallExpr>(S), Ctx);
  69. case Stmt::CXXOperatorCallExprClass:
  70. return translateCXXOperatorCallExpr(cast<CXXOperatorCallExpr>(S), Ctx);
  71. case Stmt::UnaryOperatorClass:
  72. return translateUnaryOperator(cast<UnaryOperator>(S), Ctx);
  73. case Stmt::BinaryOperatorClass:
  74. return translateBinaryOperator(cast<BinaryOperator>(S), Ctx);
  75. case Stmt::ArraySubscriptExprClass:
  76. return translateArraySubscriptExpr(cast<ArraySubscriptExpr>(S), Ctx);
  77. case Stmt::ConditionalOperatorClass:
  78. return translateConditionalOperator(cast<ConditionalOperator>(S), Ctx);
  79. case Stmt::BinaryConditionalOperatorClass:
  80. return translateBinaryConditionalOperator(
  81. cast<BinaryConditionalOperator>(S), Ctx);
  82. // We treat these as no-ops
  83. case Stmt::ParenExprClass:
  84. return translate(cast<ParenExpr>(S)->getSubExpr(), Ctx);
  85. case Stmt::ExprWithCleanupsClass:
  86. return translate(cast<ExprWithCleanups>(S)->getSubExpr(), Ctx);
  87. case Stmt::CXXBindTemporaryExprClass:
  88. return translate(cast<CXXBindTemporaryExpr>(S)->getSubExpr(), Ctx);
  89. // Collect all literals
  90. case Stmt::CharacterLiteralClass:
  91. case Stmt::CXXNullPtrLiteralExprClass:
  92. case Stmt::GNUNullExprClass:
  93. case Stmt::CXXBoolLiteralExprClass:
  94. case Stmt::FloatingLiteralClass:
  95. case Stmt::ImaginaryLiteralClass:
  96. case Stmt::IntegerLiteralClass:
  97. case Stmt::StringLiteralClass:
  98. case Stmt::ObjCStringLiteralClass:
  99. return new (Arena) til::Literal(cast<Expr>(S));
  100. case Stmt::DeclStmtClass:
  101. return translateDeclStmt(cast<DeclStmt>(S), Ctx);
  102. default:
  103. break;
  104. }
  105. if (const CastExpr *CE = dyn_cast<CastExpr>(S))
  106. return translateCastExpr(CE, Ctx);
  107. return new (Arena) til::Undefined(S);
  108. }
  109. til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE,
  110. CallingContext *Ctx) {
  111. const ValueDecl *VD = cast<ValueDecl>(DRE->getDecl()->getCanonicalDecl());
  112. // Function parameters require substitution and/or renaming.
  113. if (const ParmVarDecl *PV = dyn_cast_or_null<ParmVarDecl>(VD)) {
  114. const FunctionDecl *FD =
  115. cast<FunctionDecl>(PV->getDeclContext())->getCanonicalDecl();
  116. unsigned I = PV->getFunctionScopeIndex();
  117. if (Ctx && Ctx->FunArgs && FD == Ctx->AttrDecl->getCanonicalDecl()) {
  118. // Substitute call arguments for references to function parameters
  119. assert(I < Ctx->NumArgs);
  120. return translate(Ctx->FunArgs[I], Ctx->Prev);
  121. }
  122. // Map the param back to the param of the original function declaration
  123. // for consistent comparisons.
  124. VD = FD->getParamDecl(I);
  125. }
  126. // For non-local variables, treat it as a referenced to a named object.
  127. return new (Arena) til::LiteralPtr(VD);
  128. }
  129. til::SExpr *SExprBuilder::translateCXXThisExpr(const CXXThisExpr *TE,
  130. CallingContext *Ctx) {
  131. // Substitute for 'this'
  132. if (Ctx && Ctx->SelfArg)
  133. return translate(Ctx->SelfArg, Ctx->Prev);
  134. assert(SelfVar && "We have no variable for 'this'!");
  135. return SelfVar;
  136. }
  137. til::SExpr *SExprBuilder::translateMemberExpr(const MemberExpr *ME,
  138. CallingContext *Ctx) {
  139. til::SExpr *E = translate(ME->getBase(), Ctx);
  140. E = new (Arena) til::SApply(E);
  141. return new (Arena) til::Project(E, ME->getMemberDecl());
  142. }
  143. til::SExpr *SExprBuilder::translateCallExpr(const CallExpr *CE,
  144. CallingContext *Ctx) {
  145. // TODO -- Lock returned
  146. til::SExpr *E = translate(CE->getCallee(), Ctx);
  147. for (const auto *Arg : CE->arguments()) {
  148. til::SExpr *A = translate(Arg, Ctx);
  149. E = new (Arena) til::Apply(E, A);
  150. }
  151. return new (Arena) til::Call(E, CE);
  152. }
  153. til::SExpr *SExprBuilder::translateCXXMemberCallExpr(
  154. const CXXMemberCallExpr *ME, CallingContext *Ctx) {
  155. return translateCallExpr(cast<CallExpr>(ME), Ctx);
  156. }
  157. til::SExpr *SExprBuilder::translateCXXOperatorCallExpr(
  158. const CXXOperatorCallExpr *OCE, CallingContext *Ctx) {
  159. return translateCallExpr(cast<CallExpr>(OCE), Ctx);
  160. }
  161. til::SExpr *SExprBuilder::translateUnaryOperator(const UnaryOperator *UO,
  162. CallingContext *Ctx) {
  163. switch (UO->getOpcode()) {
  164. case UO_PostInc:
  165. case UO_PostDec:
  166. case UO_PreInc:
  167. case UO_PreDec:
  168. return new (Arena) til::Undefined(UO);
  169. // We treat these as no-ops
  170. case UO_AddrOf:
  171. case UO_Deref:
  172. case UO_Plus:
  173. return translate(UO->getSubExpr(), Ctx);
  174. case UO_Minus:
  175. case UO_Not:
  176. case UO_LNot:
  177. case UO_Real:
  178. case UO_Imag:
  179. case UO_Extension:
  180. return new (Arena)
  181. til::UnaryOp(UO->getOpcode(), translate(UO->getSubExpr(), Ctx));
  182. }
  183. return new (Arena) til::Undefined(UO);
  184. }
  185. til::SExpr *SExprBuilder::translateBinaryOperator(const BinaryOperator *BO,
  186. CallingContext *Ctx) {
  187. switch (BO->getOpcode()) {
  188. case BO_PtrMemD:
  189. case BO_PtrMemI:
  190. return new (Arena) til::Undefined(BO);
  191. case BO_Mul:
  192. case BO_Div:
  193. case BO_Rem:
  194. case BO_Add:
  195. case BO_Sub:
  196. case BO_Shl:
  197. case BO_Shr:
  198. case BO_LT:
  199. case BO_GT:
  200. case BO_LE:
  201. case BO_GE:
  202. case BO_EQ:
  203. case BO_NE:
  204. case BO_And:
  205. case BO_Xor:
  206. case BO_Or:
  207. case BO_LAnd:
  208. case BO_LOr:
  209. return new (Arena)
  210. til::BinaryOp(BO->getOpcode(), translate(BO->getLHS(), Ctx),
  211. translate(BO->getRHS(), Ctx));
  212. case BO_Assign: {
  213. const Expr *LHS = BO->getLHS();
  214. if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(LHS)) {
  215. const Expr *RHS = BO->getRHS();
  216. til::SExpr *E1 = translate(RHS, Ctx);
  217. return updateVarDecl(DRE->getDecl(), E1);
  218. }
  219. til::SExpr *E0 = translate(LHS, Ctx);
  220. til::SExpr *E1 = translate(BO->getRHS(), Ctx);
  221. return new (Arena) til::Store(E0, E1);
  222. }
  223. case BO_MulAssign:
  224. case BO_DivAssign:
  225. case BO_RemAssign:
  226. case BO_AddAssign:
  227. case BO_SubAssign:
  228. case BO_ShlAssign:
  229. case BO_ShrAssign:
  230. case BO_AndAssign:
  231. case BO_XorAssign:
  232. case BO_OrAssign:
  233. return new (Arena) til::Undefined(BO);
  234. case BO_Comma:
  235. // TODO: handle LHS
  236. return translate(BO->getRHS(), Ctx);
  237. }
  238. return new (Arena) til::Undefined(BO);
  239. }
  240. til::SExpr *SExprBuilder::translateCastExpr(const CastExpr *CE,
  241. CallingContext *Ctx) {
  242. clang::CastKind K = CE->getCastKind();
  243. switch (K) {
  244. case CK_LValueToRValue: {
  245. if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
  246. til::SExpr *E0 = lookupVarDecl(DRE->getDecl());
  247. if (E0)
  248. return E0;
  249. }
  250. til::SExpr *E0 = translate(CE->getSubExpr(), Ctx);
  251. return new (Arena) til::Load(E0);
  252. }
  253. case CK_NoOp:
  254. case CK_DerivedToBase:
  255. case CK_UncheckedDerivedToBase:
  256. case CK_ArrayToPointerDecay:
  257. case CK_FunctionToPointerDecay: {
  258. til::SExpr *E0 = translate(CE->getSubExpr(), Ctx);
  259. return E0;
  260. }
  261. default: {
  262. til::SExpr *E0 = translate(CE->getSubExpr(), Ctx);
  263. return new (Arena) til::Cast(K, E0);
  264. }
  265. }
  266. }
  267. til::SExpr *
  268. SExprBuilder::translateArraySubscriptExpr(const ArraySubscriptExpr *E,
  269. CallingContext *Ctx) {
  270. return new (Arena) til::Undefined(E);
  271. }
  272. til::SExpr *
  273. SExprBuilder::translateConditionalOperator(const ConditionalOperator *C,
  274. CallingContext *Ctx) {
  275. return new (Arena) til::Undefined(C);
  276. }
  277. til::SExpr *SExprBuilder::translateBinaryConditionalOperator(
  278. const BinaryConditionalOperator *C, CallingContext *Ctx) {
  279. return new (Arena) til::Undefined(C);
  280. }
  281. til::SExpr *
  282. SExprBuilder::translateDeclStmt(const DeclStmt *S, CallingContext *Ctx) {
  283. DeclGroupRef DGrp = S->getDeclGroup();
  284. for (DeclGroupRef::iterator I = DGrp.begin(), E = DGrp.end(); I != E; ++I) {
  285. if (VarDecl *VD = dyn_cast_or_null<VarDecl>(*I)) {
  286. Expr *E = VD->getInit();
  287. til::SExpr* SE = translate(E, Ctx);
  288. // Add local variables with trivial type to the variable map
  289. QualType T = VD->getType();
  290. if (T.isTrivialType(VD->getASTContext())) {
  291. return addVarDecl(VD, SE);
  292. }
  293. else {
  294. // TODO: add alloca
  295. }
  296. }
  297. }
  298. return nullptr;
  299. }
  300. // If (E) is non-trivial, then add it to the current basic block, and
  301. // update the statement map so that S refers to E. Returns a new variable
  302. // that refers to E.
  303. // If E is trivial returns E.
  304. til::SExpr *SExprBuilder::addStatement(til::SExpr* E, const Stmt *S,
  305. const ValueDecl *VD) {
  306. if (!E)
  307. return nullptr;
  308. if (til::ThreadSafetyTIL::isTrivial(E))
  309. return E;
  310. til::Variable *V = new (Arena) til::Variable(E, VD);
  311. V->setID(CurrentBlockID, CurrentVarID++);
  312. CurrentBB->addInstr(V);
  313. if (S)
  314. insertStmt(S, V);
  315. return V;
  316. }
  317. // Returns the current value of VD, if known, and nullptr otherwise.
  318. til::SExpr *SExprBuilder::lookupVarDecl(const ValueDecl *VD) {
  319. auto It = IdxMap.find(VD);
  320. if (It != IdxMap.end())
  321. return CurrentNameMap[It->second].second;
  322. return nullptr;
  323. }
  324. // if E is a til::Variable, update its clangDecl.
  325. inline void maybeUpdateVD(til::SExpr *E, const ValueDecl *VD) {
  326. if (!E)
  327. return;
  328. if (til::Variable *V = dyn_cast<til::Variable>(E)) {
  329. if (!V->clangDecl())
  330. V->setClangDecl(VD);
  331. }
  332. }
  333. // Adds a new variable declaration.
  334. til::SExpr *SExprBuilder::addVarDecl(const ValueDecl *VD, til::SExpr *E) {
  335. maybeUpdateVD(E, VD);
  336. IdxMap.insert(std::make_pair(VD, CurrentNameMap.size()));
  337. CurrentNameMap.makeWritable();
  338. CurrentNameMap.push_back(std::make_pair(VD, E));
  339. return E;
  340. }
  341. // Updates a current variable declaration. (E.g. by assignment)
  342. til::SExpr *SExprBuilder::updateVarDecl(const ValueDecl *VD, til::SExpr *E) {
  343. maybeUpdateVD(E, VD);
  344. auto It = IdxMap.find(VD);
  345. if (It == IdxMap.end()) {
  346. til::SExpr *Ptr = new (Arena) til::LiteralPtr(VD);
  347. til::SExpr *St = new (Arena) til::Store(Ptr, E);
  348. return St;
  349. }
  350. CurrentNameMap.makeWritable();
  351. CurrentNameMap.elem(It->second).second = E;
  352. return E;
  353. }
  354. // Merge values from Map into the current entry map.
  355. void SExprBuilder::mergeEntryMap(NameVarMap Map) {
  356. assert(CurrentBlockInfo && "Not processing a block!");
  357. if (!CurrentNameMap.valid()) {
  358. // Steal Map, using copy-on-write.
  359. CurrentNameMap = std::move(Map);
  360. return;
  361. }
  362. if (CurrentNameMap.sameAs(Map))
  363. return; // Easy merge: maps from different predecessors are unchanged.
  364. unsigned ESz = CurrentNameMap.size();
  365. unsigned MSz = Map.size();
  366. unsigned Sz = std::max(ESz, MSz);
  367. bool W = CurrentNameMap.writable();
  368. for (unsigned i=0; i<Sz; ++i) {
  369. if (CurrentNameMap[i].first != Map[i].first) {
  370. if (!W)
  371. CurrentNameMap.makeWritable();
  372. CurrentNameMap.downsize(i);
  373. break;
  374. }
  375. if (CurrentNameMap[i].second != Map[i].second) {
  376. til::Variable *V =
  377. dyn_cast<til::Variable>(CurrentNameMap[i].second);
  378. if (V && V->getBlockID() == CurrentBB->blockID()) {
  379. // We already have a Phi node, so add the new variable.
  380. til::Phi *Ph = dyn_cast<til::Phi>(V->definition());
  381. assert(Ph && "Expecting Phi node.");
  382. Ph->values()[CurrentArgIndex] = Map[i].second;
  383. }
  384. else {
  385. if (!W)
  386. CurrentNameMap.makeWritable();
  387. unsigned NPreds = CurrentBB->numPredecessors();
  388. assert(CurrentArgIndex > 0 && CurrentArgIndex < NPreds);
  389. // Make a new phi node. All phi args up to the current index must
  390. // be the same, and equal to the current NameMap value.
  391. auto *Ph = new (Arena) til::Phi(Arena, NPreds);
  392. Ph->values().setValues(NPreds, nullptr);
  393. for (unsigned PIdx = 0; PIdx < CurrentArgIndex; ++PIdx)
  394. Ph->values()[PIdx] = CurrentNameMap[i].second;
  395. Ph->values()[CurrentArgIndex] = Map[i].second;
  396. // Add phi node to current basic block.
  397. auto *Var = new (Arena) til::Variable(Ph, CurrentNameMap[i].first);
  398. Var->setID(CurrentBlockID, CurrentVarID++);
  399. CurrentBB->addArgument(Var);
  400. CurrentNameMap.elem(i).second = Var;
  401. }
  402. }
  403. }
  404. if (ESz > MSz) {
  405. if (!W)
  406. CurrentNameMap.makeWritable();
  407. CurrentNameMap.downsize(Map.size());
  408. }
  409. }
  410. void SExprBuilder::enterCFG(CFG *Cfg, const NamedDecl *D,
  411. const CFGBlock *First) {
  412. // Perform initial setup operations.
  413. unsigned NBlocks = Cfg->getNumBlockIDs();
  414. Scfg = new (Arena) til::SCFG(Arena, NBlocks);
  415. // allocate all basic blocks immediately, to handle forward references.
  416. BlockMap.reserve(NBlocks);
  417. BBInfo.resize(NBlocks);
  418. for (auto *B : *Cfg) {
  419. auto *BB = new (Arena) til::BasicBlock(Arena, 0, B->size());
  420. BlockMap.push_back(BB);
  421. }
  422. CallCtx = new SExprBuilder::CallingContext(D);
  423. }
  424. void SExprBuilder::enterCFGBlock(const CFGBlock *B) {
  425. // Intialize TIL basic block and add it to the CFG.
  426. CurrentBB = BlockMap[B->getBlockID()];
  427. CurrentBB->setBlockID(CurrentBlockID);
  428. CurrentBB->setNumPredecessors(B->pred_size());
  429. Scfg->add(CurrentBB);
  430. CurrentBlockInfo = &BBInfo[B->getBlockID()];
  431. CurrentVarID = 0;
  432. CurrentArgIndex = 0;
  433. assert(!CurrentNameMap.valid() && "CurrentNameMap already initialized.");
  434. }
  435. void SExprBuilder::handlePredecessor(const CFGBlock *Pred) {
  436. // Compute CurrentNameMap on entry from ExitMaps of predecessors
  437. BlockInfo *PredInfo = &BBInfo[Pred->getBlockID()];
  438. assert(PredInfo->SuccessorsToProcess > 0);
  439. if (--PredInfo->SuccessorsToProcess == 0)
  440. mergeEntryMap(std::move(PredInfo->ExitMap));
  441. else
  442. mergeEntryMap(PredInfo->ExitMap.clone());
  443. ++CurrentArgIndex;
  444. }
  445. void SExprBuilder::handlePredecessorBackEdge(const CFGBlock *Pred) {
  446. CurrentBlockInfo->HasBackEdges = true;
  447. }
  448. void SExprBuilder::enterCFGBlockBody(const CFGBlock *B) { }
  449. void SExprBuilder::handleStatement(const Stmt *S) {
  450. til::SExpr *E = translate(S, CallCtx);
  451. addStatement(E, S);
  452. }
  453. void SExprBuilder::handleDestructorCall(const VarDecl *VD,
  454. const CXXDestructorDecl *DD) {
  455. til::SExpr *Sf = new (Arena) til::LiteralPtr(VD);
  456. til::SExpr *Dr = new (Arena) til::LiteralPtr(DD);
  457. til::SExpr *Ap = new (Arena) til::Apply(Dr, Sf);
  458. til::SExpr *E = new (Arena) til::Call(Ap);
  459. addStatement(E, nullptr);
  460. }
  461. void SExprBuilder::exitCFGBlockBody(const CFGBlock *B) {
  462. unsigned N = B->succ_size();
  463. auto It = B->succ_begin();
  464. if (N == 1) {
  465. til::BasicBlock *BB = *It ? BlockMap[(*It)->getBlockID()] : nullptr;
  466. // TODO: set index
  467. til::SExpr *Tm = new (Arena) til::Goto(BB, 0);
  468. CurrentBB->setTerminator(Tm);
  469. }
  470. else if (N == 2) {
  471. til::SExpr *C = translate(B->getTerminatorCondition(true), CallCtx);
  472. til::BasicBlock *BB1 = *It ? BlockMap[(*It)->getBlockID()] : nullptr;
  473. ++It;
  474. til::BasicBlock *BB2 = *It ? BlockMap[(*It)->getBlockID()] : nullptr;
  475. // TODO: set conditional, set index
  476. til::SExpr *Tm = new (Arena) til::Branch(C, BB1, BB2);
  477. CurrentBB->setTerminator(Tm);
  478. }
  479. }
  480. void SExprBuilder::handleSuccessor(const CFGBlock *Succ) {
  481. ++CurrentBlockInfo->SuccessorsToProcess;
  482. }
  483. void SExprBuilder::handleSuccessorBackEdge(const CFGBlock *Succ) {
  484. }
  485. void SExprBuilder::exitCFGBlock(const CFGBlock *B) {
  486. CurrentBlockInfo->ExitMap = std::move(CurrentNameMap);
  487. CurrentBlockID++;
  488. CurrentBB = nullptr;
  489. CurrentBlockInfo = nullptr;
  490. }
  491. void SExprBuilder::exitCFG(const CFGBlock *Last) {
  492. CurrentBlockID = 0;
  493. CurrentVarID = 0;
  494. CurrentArgIndex = 0;
  495. }
  496. class LLVMPrinter : public til::PrettyPrinter<LLVMPrinter, llvm::raw_ostream> {
  497. };
  498. void printSCFG(CFGWalker &Walker) {
  499. llvm::BumpPtrAllocator Bpa;
  500. til::MemRegionRef Arena(&Bpa);
  501. SExprBuilder builder(Arena);
  502. til::SCFG *Cfg = builder.buildCFG(Walker);
  503. LLVMPrinter::print(Cfg, llvm::errs());
  504. }
  505. } // end namespace threadSafety
  506. } // end namespace clang