Skip to content

[DebugInfo] Add Verifier check for local enums in CU's enums field#185228

Merged
dzhidzhoev merged 2 commits intollvm:mainfrom
dzhidzhoev:debuginfo/verifier/local-enum/base
Mar 13, 2026
Merged

[DebugInfo] Add Verifier check for local enums in CU's enums field#185228
dzhidzhoev merged 2 commits intollvm:mainfrom
dzhidzhoev:debuginfo/verifier/local-enum/base

Conversation

@dzhidzhoev
Copy link
Copy Markdown
Member

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.ll is fixed.

This change is extracted from https://reviews.llvm.org/D144008.

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.
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Mar 7, 2026

@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-llvm-ir

Author: Vladislav Dzhidzhoev (dzhidzhoev)

Changes

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.ll is fixed.

This change is extracted from https://reviews.llvm.org/D144008.


Full diff: https://github.com/llvm/llvm-project/pull/185228.diff

2 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+4)
  • (modified) llvm/test/DebugInfo/COFF/enum-co.ll (+3-2)
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}

Copy link
Copy Markdown
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM when @phyBrackets is happy

@dzhidzhoev
Copy link
Copy Markdown
Member Author

Thank you! Updated the branch

@dzhidzhoev dzhidzhoev requested a review from phyBrackets March 12, 2026 19:38
@dzhidzhoev dzhidzhoev merged commit c5847b1 into llvm:main Mar 13, 2026
10 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants