[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
Mon Sep 25 05:04:46 PDT 2017
marco-c created this revision.
This patch fixes the crash from https://bugs.llvm.org/show_bug.cgi?id=34659.
Repository:
rL LLVM
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
@@ -637,7 +637,12 @@
int Successors = isa<ReturnInst>(TI) ? 1 : TI->getNumSuccessors();
if (Successors) {
if (Successors == 1) {
- IRBuilder<> Builder(&*BB.getFirstInsertionPt());
+ BasicBlock::iterator insertPtr = BB.getFirstInsertionPt();
+ if (insertPtr == BB.end()) {
+ continue;
+ }
+
+ IRBuilder<> Builder(&*insertPtr);
Value *Counter = Builder.CreateConstInBoundsGEP2_64(Counters, 0,
Edge);
Value *Count = Builder.CreateLoad(Counter);
@@ -670,13 +675,24 @@
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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38223.116486.patch
Type: text/x-patch
Size: 2026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170925/2667aad5/attachment.bin>
More information about the llvm-commits
mailing list