Index: llvm/lib/CodeGen/LexicalScopes.cpp =================================================================== --- llvm/lib/CodeGen/LexicalScopes.cpp +++ llvm/lib/CodeGen/LexicalScopes.cpp @@ -291,9 +291,20 @@ return; } + // The scope ranges can cover multiple basic blocks in each span. Iterate over + // all blocks (in the order they are in the function) until we reach the one + // containing the end of the span. SmallVectorImpl &InsnRanges = Scope->getRanges(); - for (auto &R : InsnRanges) - MBBs.insert(R.first->getParent()); + for (auto &R : InsnRanges) { + auto CurMBBIt = R.first->getParent()->getIterator(); + auto EndBBIt = R.second->getParent()->getIterator(); + do { + MBBs.insert(&*CurMBBIt); + if (CurMBBIt == EndBBIt) + break; + CurMBBIt++; + } while (true); + } } /// dominates - Return true if DebugLoc's lexical scope dominates at least one @@ -308,14 +319,12 @@ if (Scope == CurrentFnLexicalScope && MBB->getParent() == MF) return true; - bool Result = false; - for (auto &I : *MBB) { - if (const DILocation *IDL = I.getDebugLoc()) - if (LexicalScope *IScope = getOrCreateLexicalScope(IDL)) - if (Scope->dominates(IScope)) - return true; - } - return Result; + // Fetch all the blocks in DLs scope. Because the range / block list also + // contain any subscopes, any instruction that DL dominates can be found + // in the block set. + SmallPtrSet Set; + getMachineBasicBlocks(DL, Set); + return Set.count(MBB) != 0; } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)