[DebugInfo] Add Verifier check for local enums in CU's enums field#185228
Merged
dzhidzhoev merged 2 commits intollvm:mainfrom Mar 13, 2026
Merged
[DebugInfo] Add Verifier check for local enums in CU's enums field#185228dzhidzhoev merged 2 commits intollvm:mainfrom
dzhidzhoev merged 2 commits intollvm:mainfrom
Conversation
Since llvm#165032, DwarfDebug asserts if function-local enums are present in the enums field of DICompileUnit. This patch adds a check to the Verifier to detect such invalid IR earlier. Incorrect occurence of a local enum in DICompileUnit's enums field in llvm/test/DebugInfo/COFF/enum-co.ll is fixed. This change is extracted from https://reviews.llvm.org/D144008.
Member
|
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-llvm-ir Author: Vladislav Dzhidzhoev (dzhidzhoev) ChangesSince #165032, DwarfDebug asserts if function-local enums are present in the enums field of DICompileUnit. Incorrect occurence of a local enum in DICompileUnit's enums field in This change is extracted from https://reviews.llvm.org/D144008. 2 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f986f5406b2b3..0bf3141289680 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1574,6 +1574,10 @@ void Verifier::visitDICompileUnit(const DICompileUnit &N) {
auto *Enum = dyn_cast_or_null<DICompositeType>(Op);
CheckDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type,
"invalid enum type", &N, N.getEnumTypes(), Op);
+ if (Enum->getScope())
+ CheckDI(!isa<DILocalScope>(Enum->getScope()),
+ "function-local enum in a DICompileUnit's enum list", &N,
+ N.getEnumTypes(), Op);
}
}
if (auto *Array = N.getRawRetainedTypes()) {
diff --git a/llvm/test/DebugInfo/COFF/enum-co.ll b/llvm/test/DebugInfo/COFF/enum-co.ll
index a334b353e009a..d333577550494 100644
--- a/llvm/test/DebugInfo/COFF/enum-co.ll
+++ b/llvm/test/DebugInfo/COFF/enum-co.ll
@@ -134,7 +134,7 @@ attributes #1 = { nounwind readnone speculatable }
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "enum-co.cpp", directory: "D:\5Cupstream\5Cllvm\5Ctest\5CDebugInfo\5CCOFF", checksumkind: CSK_MD5, checksum: "2e53b90441669acca735bad28ed3a1ab")
-!2 = !{!3, !8, !13, !18}
+!2 = !{!3, !8, !18}
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !1, line: 4, baseType: !4, size: 32, elements: !5, identifier: ".?AW4Enum@@")
!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!5 = !{!6, !7}
@@ -146,7 +146,7 @@ attributes #1 = { nounwind readnone speculatable }
!11 = !DIEnumerator(name: "BLUE", value: 1)
!12 = !DIEnumerator(name: "NOTCARE", value: 2)
!13 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "ScopedEnum", scope: !14, file: !1, line: 11, baseType: !4, size: 32, elements: !5, identifier: ".?AW4ScopedEnum@?1??Func@@YAXXZ@")
-!14 = distinct !DISubprogram(name: "Func", linkageName: "?Func@@YAXXZ", scope: !1, file: !1, line: 10, type: !15, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !17)
+!14 = distinct !DISubprogram(name: "Func", linkageName: "?Func@@YAXXZ", scope: !1, file: !1, line: 10, type: !15, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !47)
!15 = !DISubroutineType(types: !16)
!16 = !{null}
!17 = !{}
@@ -179,3 +179,4 @@ attributes #1 = { nounwind readnone speculatable }
!44 = !DILocalVariable(name: "S", scope: !14, file: !1, line: 20, type: !20)
!45 = !DILocation(line: 20, scope: !14)
!46 = !DILocation(line: 21, scope: !14, isImplicitCode: true)
+!47 = !{!13}
|
phyBrackets
reviewed
Mar 9, 2026
phyBrackets
requested changes
Mar 9, 2026
OCHyams
approved these changes
Mar 9, 2026
Contributor
OCHyams
left a comment
There was a problem hiding this comment.
LGTM when @phyBrackets is happy
Member
Author
|
Thank you! Updated the branch |
phyBrackets
approved these changes
Mar 13, 2026
albertbolt1
pushed a commit
to albertbolt1/llvm-project
that referenced
this pull request
Mar 13, 2026
…lvm#185228) Since llvm#165032, DwarfDebug asserts if function-local enums are present in the enums field of DICompileUnit. This patch adds a check to the Verifier to detect such invalid IR earlier. Incorrect occurence of a local enum in DICompileUnit's enums field in `llvm/test/DebugInfo/COFF/enum-co.ll` is fixed. This change is extracted from https://reviews.llvm.org/D144008.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #165032, DwarfDebug asserts if function-local enums are present in the enums field of DICompileUnit.
This patch adds a check to the Verifier to detect such invalid IR earlier.
Incorrect occurence of a local enum in DICompileUnit's enums field in
llvm/test/DebugInfo/COFF/enum-co.llis fixed.This change is extracted from https://reviews.llvm.org/D144008.