Skip to content

Commit 653872f

Browse files
authored
[KeyInstr] Fix verifier check (#149043)
The verifier check was in the wrong place, meaning it wasn't actually checking many instructions. Fixing that causes a test failure (coro-dwarf-key-instrs.cpp) because coros turn off the feature but still annotate instructions with the metadata (which is a supported situation, but the verifier doesn't like it, and it's hard to teach the verifier to like it). Fix that by avoiding emitting any key instruction metadata if the DISubprogram has opted out of key instructions.
1 parent 60579ec commit 653872f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ void CGDebugInfo::addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction,
170170
if (!Group || !CGM.getCodeGenOpts().DebugKeyInstructions)
171171
return;
172172

173+
llvm::DISubprogram *SP = KeyInstruction->getFunction()->getSubprogram();
174+
if (!SP || !SP->getKeyInstructionsEnabled())
175+
return;
176+
173177
addInstSourceAtomMetadata(KeyInstruction, Group, /*Rank=*/1);
174178

175179
llvm::Instruction *BackupI =

llvm/lib/IR/Verifier.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,12 +3185,6 @@ void Verifier::visitFunction(const Function &F) {
31853185
CheckDI(SP->describes(&F),
31863186
"!dbg attachment points at wrong subprogram for function", N, &F,
31873187
&I, DL, Scope, SP);
3188-
3189-
if (DL->getAtomGroup())
3190-
CheckDI(DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
3191-
"DbgLoc uses atomGroup but DISubprogram doesn't have Key "
3192-
"Instructions enabled",
3193-
DL, DL->getScope()->getSubprogram());
31943188
};
31953189
for (auto &BB : F)
31963190
for (auto &I : BB) {
@@ -5492,6 +5486,15 @@ void Verifier::visitInstruction(Instruction &I) {
54925486
if (MDNode *N = I.getDebugLoc().getAsMDNode()) {
54935487
CheckDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N);
54945488
visitMDNode(*N, AreDebugLocsAllowed::Yes);
5489+
5490+
if (auto *DL = dyn_cast<DILocation>(N)) {
5491+
if (DL->getAtomGroup()) {
5492+
CheckDI(DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
5493+
"DbgLoc uses atomGroup but DISubprogram doesn't have Key "
5494+
"Instructions enabled",
5495+
DL, DL->getScope()->getSubprogram());
5496+
}
5497+
}
54955498
}
54965499

54975500
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {

llvm/test/DebugInfo/KeyInstructions/Generic/verify.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
define dso_local void @f() !dbg !10 {
99
entry:
10+
; Include non-key location to check verifier is checking the whole function.
11+
%0 = add i32 0, 0, !dbg !14
1012
ret void, !dbg !13
1113
}
1214

@@ -20,3 +22,4 @@ entry:
2022
!11 = !DISubroutineType(types: !12)
2123
!12 = !{null}
2224
!13 = !DILocation(line: 1, column: 11, scope: !10, atomGroup: 1, atomRank: 1)
25+
!14 = !DILocation(line: 1, column: 11, scope: !10)

0 commit comments

Comments
 (0)