Skip to content

Commit a27da0a

Browse files
authored
[llvm][MetadataLoader] Make sure we correctly load DW_APPLE_ENUM_KIND from bitcode (#132374)
This was pointed out in #124752 (comment) There was no test that roundtrips this attribute through LLVM bitcode, so this was never caught.
1 parent 6c8e9a6 commit a27da0a

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
17041704
}
17051705
}
17061706

1707-
if (Record.size() > 25 && Record[25] != dwarf::DW_APPLE_ENUM_KIND_invalid)
1708-
EnumKind = Record[25];
1707+
if (Record.size() > 24 && Record[24] != dwarf::DW_APPLE_ENUM_KIND_invalid)
1708+
EnumKind = Record[24];
17091709

17101710
DICompositeType *CT = nullptr;
17111711
if (Identifier)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s --check-prefix=CHECK-METADATA
2+
3+
; C++ source to regenerate:
4+
; enum __attribute__((enum_extensibility(open))) OpenEnum {
5+
; oe1
6+
; } oe;
7+
;
8+
; enum __attribute__((enum_extensibility(closed))) ClosedEnum {
9+
; ce1
10+
; } ce;
11+
;
12+
; $ clang++ -O0 -g debug-info-enum-kind.cpp -c
13+
14+
; CHECK-METADATA: enumKind: DW_APPLE_ENUM_KIND_Open
15+
; CHECK-METADATA: enumKind: DW_APPLE_ENUM_KIND_Closed
16+
17+
source_filename = "enum.cpp"
18+
target triple = "arm64-apple-macosx"
19+
20+
@oe = global i32 0, align 4, !dbg !0
21+
@ce = global i32 0, align 4, !dbg !13
22+
23+
!llvm.dbg.cu = !{!2}
24+
!llvm.module.flags = !{!15, !16}
25+
26+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
27+
!1 = distinct !DIGlobalVariable(name: "oe", scope: !2, file: !3, line: 3, type: !5, isLocal: false, isDefinition: true)
28+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !12, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
29+
!3 = !DIFile(filename: "enum.cpp", directory: "/tmp")
30+
!4 = !{!5, !9}
31+
!5 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "OpenEnum", file: !3, line: 1, baseType: !6, size: 32, elements: !7, identifier: "_ZTS8OpenEnum", enumKind: DW_APPLE_ENUM_KIND_Open)
32+
!6 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
33+
!7 = !{!8}
34+
!8 = !DIEnumerator(name: "oe1", value: 0, isUnsigned: true)
35+
!9 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "ClosedEnum", file: !3, line: 5, baseType: !6, size: 32, elements: !10, identifier: "_ZTS10ClosedEnum", enumKind: DW_APPLE_ENUM_KIND_Closed)
36+
!10 = !{!11}
37+
!11 = !DIEnumerator(name: "ce1", value: 0, isUnsigned: true)
38+
!12 = !{!0, !13}
39+
!13 = !DIGlobalVariableExpression(var: !14, expr: !DIExpression())
40+
!14 = distinct !DIGlobalVariable(name: "ce", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true)
41+
!15 = !{i32 7, !"Dwarf Version", i32 5}
42+
!16 = !{i32 2, !"Debug Info Version", i32 3}

0 commit comments

Comments
 (0)