Skip to content

Commit 6ce2a6f

Browse files
[DebugInfo] Fix getScopeOfFirstNonMetaInstruction
This function is clearly returning the opposite of what its name says: ``` const SILDebugScope *SILBasicBlock::getScopeOfFirstNonMetaInstruction() { for (auto &Inst : *this) if (Inst.isMetaInstruction()) return Inst.getDebugScope(); return begin()->getDebugScope(); } ``` Looking at the PR history (sadly GH doesn't preserve old versions of the patch...) #15575 There was this snippet of code: ``` // Find the correct debug scope for alloc stack. We want to give to the // expanded sequence the correct debug scope so we skip over instructions // that aren't lowered to anything real (e.g. debug_value). static const SILDebugScope *findAllocStackDebugScope(SILBasicBlock &BB) { auto It = BB.begin(); while (It != BB.end()) { if (!isMaintenanceInst(&*It)) ``` We don't know what used to be after that line but, based on the comments, it must have been a `return It->getDebugScope()`. Adrian then asked the author to make this a different helper function `getScopeOfFirstNonMetaInstruction`, and the subsequence force-push had the code we see today. So maybe it was in this conversion that the author made the mistake? Fixing the implementation doesn't cause any tests to fail (sadly the original PR did not add any SIL->SIL tests, which would have been ideal).
1 parent c5840e8 commit 6ce2a6f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ bool SILBasicBlock::hasPhi() const {
441441

442442
const SILDebugScope *SILBasicBlock::getScopeOfFirstNonMetaInstruction() {
443443
for (auto &Inst : *this)
444-
if (Inst.isMetaInstruction())
444+
if (!Inst.isMetaInstruction())
445445
return Inst.getDebugScope();
446446
return begin()->getDebugScope();
447447
}

0 commit comments

Comments
 (0)