@@ -79,30 +79,46 @@ LLVMBasedCFG::getPredsOf(const llvm::Instruction *I) const {
7979
8080vector<const llvm::Instruction *>
8181LLVMBasedCFG::getSuccsOf (const llvm::Instruction *I) const {
82- std:: vector<const llvm::Instruction *> Successors;
82+ vector<const llvm::Instruction *> Successors;
8383 // case we wish to consider LLVM's debug instructions
8484 if (!IgnoreDbgInstructions) {
85- if (auto *NextInst = I->getNextNode ()) {
86- return { NextInst} ;
85+ if (const auto *NextInst = I->getNextNode ()) {
86+ Successors. push_back ( NextInst) ;
8787 }
8888 } else {
89- if (auto *NextNonDbgInst =
89+ if (const auto *NextNonDbgInst =
9090 I->getNextNonDebugInstruction (false /* Only debug instructions*/ )) {
9191 Successors.push_back (NextNonDbgInst);
9292 }
9393 }
94- if (I->isTerminator ()) {
95- Successors.reserve (I->getNumSuccessors () + Successors.size ());
96- std::transform (llvm::succ_begin (I), llvm::succ_end (I),
97- back_inserter (Successors), [](const llvm::BasicBlock *BB) {
98- const llvm::Instruction *Succ = &BB->front ();
99- if (llvm::isa<llvm::DbgInfoIntrinsic>(Succ)) {
100- Succ = Succ->getNextNonDebugInstruction (
101- false /* Only debug instructions*/ );
102- }
103- return Succ;
104- });
94+
95+ if (Successors.empty ()) {
96+ if (const auto *Branch = llvm::dyn_cast<llvm::BranchInst>(I);
97+ Branch && isStaticVariableLazyInitializationBranch (Branch)) {
98+ // Skip the "already initialized" case, such that the analysis is always
99+ // aware of the initialized value.
100+ const auto *NextInst = &Branch->getSuccessor (0 )->front ();
101+ if (IgnoreDbgInstructions &&
102+ llvm::isa<llvm::DbgInfoIntrinsic>(NextInst)) {
103+ NextInst = NextInst->getNextNonDebugInstruction (false );
104+ }
105+ Successors.push_back (NextInst);
106+
107+ } else {
108+ Successors.reserve (I->getNumSuccessors () + Successors.size ());
109+ std::transform (llvm::succ_begin (I), llvm::succ_end (I),
110+ std::back_inserter (Successors),
111+ [](const llvm::BasicBlock *BB) {
112+ const llvm::Instruction *Succ = &BB->front ();
113+ if (llvm::isa<llvm::DbgInfoIntrinsic>(Succ)) {
114+ Succ = Succ->getNextNonDebugInstruction (
115+ false /* Only debug instructions*/ );
116+ }
117+ return Succ;
118+ });
119+ }
105120 }
121+
106122 return Successors;
107123}
108124
0 commit comments