diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 3784ee00811f..af5f98ca8865 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1574,6 +1574,9 @@ void Verifier::visitDICompileUnit(const DICompileUnit &N) { auto *Enum = dyn_cast_or_null(Op); CheckDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type, "invalid enum type", &N, N.getEnumTypes(), Op); + CheckDI(!Enum->getScope() || !isa(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 a334b353e009..d33357755049 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}