Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -502,6 +502,16 @@ 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 @@ // 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);