[PATCH] D38223: Make sure the basic block has an insertion point before dereferencing it
Marco Castelluccio via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 4 12:57:23 PDT 2017
marco-c updated this revision to Diff 117716.
marco-c added a comment.
Updated patch to add catchswitch successors to ComplexEdgeSuccs
https://reviews.llvm.org/D38223
Files:
lib/Transforms/Instrumentation/GCOVProfiling.cpp
Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp
===================================================================
--- lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -646,7 +646,7 @@
TerminatorInst *TI = BB.getTerminator();
int Successors = isa<ReturnInst>(TI) ? 1 : TI->getNumSuccessors();
if (Successors) {
- if (Successors == 1) {
+ if (Successors == 1 && !isa<CatchSwitchInst>(TI)) {
IRBuilder<> Builder(&*BB.getFirstInsertionPt());
Value *Counter = Builder.CreateConstInBoundsGEP2_64(Counters, 0,
Edge);
@@ -680,13 +680,21 @@
GlobalVariable *EdgeState = getEdgeStateValue();
for (int i = 0, e = ComplexEdgePreds.size(); i != e; ++i) {
- IRBuilder<> Builder(&*ComplexEdgePreds[i + 1]->getFirstInsertionPt());
+ auto *BB = ComplexEdgePreds[i + 1];
+ BasicBlock::iterator insertPtr = BB->getFirstInsertionPt();
+ if (insertPtr == BB->end()) continue;
+
+ IRBuilder<> Builder(&*insertPtr);
Builder.CreateStore(Builder.getInt32(i), EdgeState);
}
for (int i = 0, e = ComplexEdgeSuccs.size(); i != e; ++i) {
+ auto *BB = ComplexEdgeSuccs[i + 1];
+ BasicBlock::iterator insertPtr = BB->getFirstInsertionPt();
+ if (insertPtr == BB->end()) continue;
+
// Call runtime to perform increment.
- IRBuilder<> Builder(&*ComplexEdgeSuccs[i + 1]->getFirstInsertionPt());
+ IRBuilder<> Builder(&*insertPtr);
Value *CounterPtrArray =
Builder.CreateConstInBoundsGEP2_64(EdgeTable, 0,
i * ComplexEdgePreds.size());
@@ -764,7 +772,7 @@
for (BasicBlock &BB : *F) {
TerminatorInst *TI = BB.getTerminator();
int Successors = isa<ReturnInst>(TI) ? 1 : TI->getNumSuccessors();
- if (Successors > 1 && !isa<BranchInst>(TI) && !isa<ReturnInst>(TI)) {
+ if ((Successors > 1 && !isa<BranchInst>(TI)) || isa<CatchSwitchInst>(TI)) {
for (int i = 0; i != Successors; ++i) {
BasicBlock *Succ = TI->getSuccessor(i);
IRBuilder<> Builder(Succ);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38223.117716.patch
Type: text/x-patch
Size: 2283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171004/88f2c250/attachment.bin>
More information about the llvm-commits
mailing list