From 71e7a8ba8994e5b1f9cc0a0986b2ef5d37ed8ad2 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 26 Sep 2017 11:56:43 +0000 Subject: [PATCH] Don't move llvm.localescape outside the entry block in the GCOV profiling pass Summary: This fixes https://bugs.llvm.org/show_bug.cgi?id=34714. Patch by Marco Castelluccio Reviewers: rnk Reviewed By: rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38224 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314201 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Instrumentation/GCOVProfiling.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index b2033536ac8..3154c1939ea 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -502,6 +502,16 @@ static bool functionHasLines(Function &F) { return false; } +static bool shouldKeepInEntry(BasicBlock::iterator It) { + if (isa(*It)) return true; + if (isa(*It)) return true; + if (auto *II = dyn_cast(It)) { + if (II->getIntrinsicID() == llvm::Intrinsic::localescape) return true; + } + + return false; +} + void GCOVProfiler::emitProfileNotes() { NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu"); if (!CU_Nodes) return; @@ -537,7 +547,7 @@ void GCOVProfiler::emitProfileNotes() { // single successor, so split the entry block to make sure of that. BasicBlock &EntryBlock = F.getEntryBlock(); BasicBlock::iterator It = EntryBlock.begin(); - while (isa(*It) || isa(*It)) + while (shouldKeepInEntry(It)) ++It; EntryBlock.splitBasicBlock(It); -- 2.40.0