[KeyInstr] Fix verifier check#149043
Conversation
|
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-clang Author: Orlando Cazalet-Hyams (OCHyams) ChangesThe 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. Full diff: https://github.com/llvm/llvm-project/pull/149043.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index f97c7b6445984..0dde045453e3a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -170,6 +170,10 @@ void CGDebugInfo::addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction,
if (!Group || !CGM.getCodeGenOpts().DebugKeyInstructions)
return;
+ llvm::DISubprogram *SP = KeyInstruction->getFunction()->getSubprogram();
+ if (!SP || !SP->getKeyInstructionsEnabled())
+ return;
+
addInstSourceAtomMetadata(KeyInstruction, Group, /*Rank=*/1);
llvm::Instruction *BackupI =
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 8004077b92665..ccaa8ccba085d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3185,12 +3185,6 @@ void Verifier::visitFunction(const Function &F) {
CheckDI(SP->describes(&F),
"!dbg attachment points at wrong subprogram for function", N, &F,
&I, DL, Scope, SP);
-
- if (DL->getAtomGroup())
- CheckDI(DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
- "DbgLoc uses atomGroup but DISubprogram doesn't have Key "
- "Instructions enabled",
- DL, DL->getScope()->getSubprogram());
};
for (auto &BB : F)
for (auto &I : BB) {
@@ -5492,6 +5486,13 @@ void Verifier::visitInstruction(Instruction &I) {
if (MDNode *N = I.getDebugLoc().getAsMDNode()) {
CheckDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N);
visitMDNode(*N, AreDebugLocsAllowed::Yes);
+
+ auto *DL = cast<DILocation>(N);
+ if (DL->getAtomGroup())
+ CheckDI(DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
+ "DbgLoc uses atomGroup but DISubprogram doesn't have Key "
+ "Instructions enabled",
+ DL, DL->getScope()->getSubprogram());
}
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
|
jmorse
left a comment
There was a problem hiding this comment.
Given that we've found a verifier error that necessitates this patch, it presumably wants a test.
|
So just to makes sure my understanding is correct: we have an existing bug and an existing test which should exercise that bug, but the verifier doesn't catch it currently. This patch then fixes both the verifier and the bug, and therefore a new test isn't needed for the non-verifier change because the coverage for the non-verifier change already exists in |
|
So, to be clear:
I suppose I could add a check for the verifier condition independently of coro-dwarf-key-instrs.cpp ... coming right up |
SLTozer
left a comment
There was a problem hiding this comment.
LGTM with some inline nits.
| if (DL->getAtomGroup()) | ||
| CheckDI(DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(), | ||
| "DbgLoc uses atomGroup but DISubprogram doesn't have Key " | ||
| "Instructions enabled", | ||
| DL, DL->getScope()->getSubprogram()); |
|
|
||
| define dso_local void @f() !dbg !10 { | ||
| entry: | ||
| ; include non-key location to check verifier is checking the whole function. |
There was a problem hiding this comment.
| ; include non-key location to check verifier is checking the whole function. | |
| ; Include non-key location to check verifier is checking the whole function. |
|
/cherry-pick 653872f |
|
/pull-request #149053 |
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. (cherry picked from commit 653872f)
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.