-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DebugInfo][LLVM IR] Verifier checks for the extraData #167971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[DebugInfo][LLVM IR] Verifier checks for the extraData #167971
Conversation
|
@llvm/pr-subscribers-llvm-ir Author: Laxman Sole (laxmansole) ChangesLLVM IR verifier checks for This is a follow-up PR based on discussions in #165023 Full diff: https://github.com/llvm/llvm-project/pull/167971.diff 1 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index fa18c3cd0f404..b01ca73aa3623 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1320,6 +1320,23 @@ void Verifier::visitDIDerivedType(const DIDerivedType &N) {
if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
CheckDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N,
N.getRawExtraData());
+ } else if (N.getTag() == dwarf::DW_TAG_template_alias) {
+ CheckDI(isa<MDTuple>(N.getRawExtraData()), "invalid template parameters",
+ &N, N.getRawExtraData());
+ } else if (auto *ExtraData = N.getRawExtraData()) {
+ auto IsValidExtraData = [&]() {
+ if (isa<ConstantAsMetadata>(ExtraData) || isa<MDString>(ExtraData) ||
+ isa<DIObjCProperty>(ExtraData))
+ return true;
+ if (auto *Tuple = dyn_cast<MDTuple>(ExtraData))
+ return Tuple->getNumOperands() == 1 &&
+ isa<ConstantAsMetadata>(Tuple->getOperand(0));
+ return false;
+ };
+ CheckDI(IsValidExtraData(),
+ "extraData must be ConstantAsMetadata, MDString, DIObjCProperty, "
+ "or MDTuple with single ConstantAsMetadata operand",
+ &N, ExtraData);
}
if (N.getTag() == dwarf::DW_TAG_set_type) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds LLVM IR verifier checks for the extraData field in DIDerivedType debug info metadata. The changes ensure that extraData contains only valid metadata types based on the debug info tag, preventing invalid metadata from being created.
Key Changes:
- Added validation for
DW_TAG_template_aliasto ensureextraDatais anMDTuple - Added general validation for all other tags with
extraDatato restrict it to specific allowed metadata types
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| auto IsValidExtraData = [&]() { | ||
| if (isa<ConstantAsMetadata>(ExtraData) || isa<MDString>(ExtraData) || | ||
| isa<DIObjCProperty>(ExtraData)) | ||
| return true; | ||
| if (auto *Tuple = dyn_cast<MDTuple>(ExtraData)) | ||
| return Tuple->getNumOperands() == 1 && | ||
| isa<ConstantAsMetadata>(Tuple->getOperand(0)); | ||
| return false; | ||
| }; |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda does not validate that an MDTuple with a single operand actually contains a ConstantAsMetadata. If getOperand(0) returns null, the check will pass but may lead to undefined behavior. Add a null check before calling isa<ConstantAsMetadata>.
|
Test? |
llvm/lib/IR/Verifier.cpp
Outdated
| CheckDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N, | ||
| N.getRawExtraData()); | ||
| } else if (N.getTag() == dwarf::DW_TAG_template_alias) { | ||
| CheckDI(isa<MDTuple>(N.getRawExtraData()), "invalid template parameters", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't crash if N.getRawExtraData() returns nullptr. (also relevant for the fragment reviewed by Copilot)
llvm/lib/IR/Verifier.cpp
Outdated
| if (isa<ConstantAsMetadata>(ExtraData) || isa<MDString>(ExtraData) || | ||
| isa<DIObjCProperty>(ExtraData)) | ||
| return true; | ||
| if (auto *Tuple = dyn_cast<MDTuple>(ExtraData)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow this only for DW_TAG_member, DW_TAG_variable, and DW_TAG_inheritance tags?
1423cbb to
f583bc3
Compare
LLVM IR verifier checks for
extraDatain debug info metadata.This is a follow-up PR based on discussions in #165023