Skip to content

Commit cdf30f0

Browse files
authored
[llvm][DebugInfo] Fix set debug validation with the addition of the new subrange debug (llvm#154665)
Set debug was failing validation where the base type was subrange. This has happened with the addition of the new functionality for proper subrange debugging. This fix just allows set types to be based on subranges.
1 parent 9470113 commit cdf30f0

File tree

2 files changed

+94
-73
lines changed

2 files changed

+94
-73
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,9 +1298,11 @@ void Verifier::visitDIDerivedType(const DIDerivedType &N) {
12981298
if (N.getTag() == dwarf::DW_TAG_set_type) {
12991299
if (auto *T = N.getRawBaseType()) {
13001300
auto *Enum = dyn_cast_or_null<DICompositeType>(T);
1301+
auto *Subrange = dyn_cast_or_null<DISubrangeType>(T);
13011302
auto *Basic = dyn_cast_or_null<DIBasicType>(T);
13021303
CheckDI(
13031304
(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1305+
(Subrange && Subrange->getTag() == dwarf::DW_TAG_subrange_type) ||
13041306
(Basic && (Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
13051307
Basic->getEncoding() == dwarf::DW_ATE_signed ||
13061308
Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||

llvm/test/DebugInfo/X86/set.ll

Lines changed: 92 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,112 +5,131 @@
55

66
; ModuleID = 'Main.mb'
77
source_filename = "../src/Main.m3"
8-
target datalayout = "e-m:e-p:64:64-i64:64-f80:128-n8:16:32:64-S128"
8+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-p:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
99
target triple = "x86_64-pc-linux-gnu"
1010

11-
%M_Const_struct = type { [7 x i8], [1 x i8], [4 x i8], [4 x i8], ptr, ptr, ptr, ptr, [8 x i8], [14 x i8], [2 x i8] }
11+
%M_Const_struct = type { [8 x i8], i64, [16 x i8], [7 x i8], [1 x i8], [4 x i8], [4 x i8], ptr, ptr, ptr, ptr, [8 x i8], [14 x i8], [2 x i8] }
1212
%M_Main_struct = type { ptr, [32 x i8], ptr, [24 x i8], ptr, [8 x i8], ptr, i64, [8 x i8], ptr, ptr, [8 x i8], ptr, [8 x i8] }
13+
%struct.0 = type { [32 x i8] }
1314

14-
@M_Const = internal constant %M_Const_struct { [7 x i8] c"Main_M3", [1 x i8] zeroinitializer, [4 x i8] c"Test", [4 x i8] zeroinitializer, ptr @Main_M3, ptr @M_Const, ptr @Main__Test, ptr getelementptr inbounds (i8, ptr @M_Const, i64 8), [8 x i8] zeroinitializer, [14 x i8] c"../src/Main.m3", [2 x i8] zeroinitializer }, align 8
15-
@M_Main = internal global %M_Main_struct { ptr getelementptr inbounds (i8, ptr @M_Const, i64 56), [32 x i8] zeroinitializer, ptr getelementptr inbounds (i8, ptr @M_Const, i64 16), [24 x i8] zeroinitializer, ptr getelementptr inbounds (i8, ptr @M_Main, i64 104), [8 x i8] zeroinitializer, ptr @Main_M3, i64 3, [8 x i8] zeroinitializer, ptr @Main_I3, ptr getelementptr inbounds (i8, ptr @M_Main, i64 128), [8 x i8] zeroinitializer, ptr @RTHooks_I3, [8 x i8] zeroinitializer }, align 8
15+
@M_Const = internal constant %M_Const_struct { [8 x i8] zeroinitializer, i64 65546, [16 x i8] zeroinitializer, [7 x i8] c"Main_M3", [1 x i8] zeroinitializer, [4 x i8] c"Test", [4 x i8] zeroinitializer, ptr @Main_M3, ptr getelementptr inbounds (i8, ptr @M_Const, i64 32), ptr @Main__Test, ptr getelementptr inbounds (i8, ptr @M_Const, i64 40), [8 x i8] zeroinitializer, [14 x i8] c"../src/Main.m3", [2 x i8] zeroinitializer }, align 8
16+
@M_Main = internal global %M_Main_struct { ptr getelementptr inbounds (i8, ptr @M_Const, i64 88), [32 x i8] zeroinitializer, ptr getelementptr inbounds (i8, ptr @M_Const, i64 48), [24 x i8] zeroinitializer, ptr getelementptr inbounds (i8, ptr @M_Main, i64 104), [8 x i8] zeroinitializer, ptr @Main_M3, i64 3, [8 x i8] zeroinitializer, ptr @Main_I3, ptr getelementptr inbounds (i8, ptr @M_Main, i64 128), [8 x i8] zeroinitializer, ptr @RTHooks_I3, [8 x i8] zeroinitializer }, align 8
1617
@m3_jmpbuf_size = external global i64, align 8
1718

19+
declare ptr @__m3_personality_v0()
20+
1821
declare ptr @Main_I3()
1922

2023
declare ptr @RTHooks_I3()
2124

22-
; Function Attrs: uwtable
23-
define void @Main__Test() #0 !dbg !5 {
25+
define void @Main__Test() #0 !dbg !18 {
2426
entry:
2527
%as = alloca i64, align 8
26-
%bs = alloca i64, align 8
27-
br label %second, !dbg !21
28+
%bs = alloca i8, align 1
29+
%sc = alloca %struct.0, align 8
30+
%sb = alloca i8, align 1
31+
br label %second, !dbg !22
2832

2933
second: ; preds = %entry
30-
call void @llvm.dbg.declare(metadata ptr %as, metadata !22, metadata !DIExpression()), !dbg !25
31-
call void @llvm.dbg.declare(metadata ptr %bs, metadata !26, metadata !DIExpression()), !dbg !25
32-
store i64 36028797018972298, ptr %as, align 8, !dbg !28
33-
store i64 197, ptr %bs, align 8, !dbg !29
34-
ret void, !dbg !21
34+
#dbg_declare(ptr %as, !23, !DIExpression(), !27)
35+
#dbg_declare(ptr %bs, !28, !DIExpression(), !27)
36+
#dbg_declare(ptr %sc, !30, !DIExpression(), !27)
37+
#dbg_declare(ptr %sb, !33, !DIExpression(), !27)
38+
store i8 3, ptr %sb, align 1, !dbg !36
39+
store i64 36028797018972298, ptr %as, align 8, !dbg !37
40+
store i8 85, ptr %bs, align 1, !dbg !38
41+
call void @llvm.memmove.p0.p0.i64(ptr align 8 %sc, ptr align 8 @M_Const, i64 32, i1 false), !dbg !39
42+
ret void, !dbg !22
3543
}
3644

37-
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
38-
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
39-
4045
declare ptr @alloca()
4146

42-
; Function Attrs: uwtable
43-
define ptr @Main_M3(i64 %mode) #0 !dbg !30 {
47+
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
48+
declare void @llvm.memmove.p0.p0.i64(ptr writeonly captures(none), ptr readonly captures(none), i64, i1 immarg) #1
49+
50+
define ptr @Main_M3(i64 %mode) #0 !dbg !40 {
4451
entry:
4552
%mode1 = alloca i64, align 8
4653
store i64 %mode, ptr %mode1, align 8
47-
br label %second, !dbg !36
54+
br label %second, !dbg !45
4855

4956
second: ; preds = %entry
50-
call void @llvm.dbg.declare(metadata ptr %mode1, metadata !37, metadata !DIExpression()), !dbg !38
51-
%v.3 = load i64, ptr %mode1, align 8, !dbg !38
52-
%icmp = icmp eq i64 %v.3, 0, !dbg !38
53-
br i1 %icmp, label %if_1, label %else_1, !dbg !38
57+
#dbg_declare(ptr %mode1, !46, !DIExpression(), !47)
58+
%v.3 = load i64, ptr %mode1, align 8, !dbg !47
59+
%icmp = icmp eq i64 %v.3, 0, !dbg !47
60+
br i1 %icmp, label %if_1, label %else_1, !dbg !47
5461

5562
else_1: ; preds = %second
56-
call void @Main__Test(), !dbg !36
57-
br label %if_1, !dbg !36
63+
call void @Main__Test(), !dbg !45
64+
br label %if_1, !dbg !45
5865

5966
if_1: ; preds = %else_1, %second
60-
ret ptr @M_Main, !dbg !36
67+
ret ptr @M_Main, !dbg !45
6168
}
6269

63-
attributes #0 = { uwtable "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
64-
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
65-
66-
!llvm.ident = !{!0}
67-
!llvm.dbg.cu = !{!1}
68-
!llvm.module.flags = !{!18, !19, !20}
69-
70-
!0 = !{!"versions- cm3: d5.10.0 llvm: 9.0"}
71-
!1 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !2, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
72-
!2 = !DIFile(filename: "Main.m3", directory: "/home/cm3/settest/src")
73-
!3 = !{!4}
74-
!4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", scope: !5, file: !2, line: 11, size: 8, align: 8, elements: !9)
75-
!5 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !2, file: !2, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
76-
!6 = !DISubroutineType(types: !7)
77-
!7 = !{null}
78-
!8 = !{}
79-
!9 = !{!10, !11, !12, !13, !14, !15, !16, !17}
80-
!10 = !DIEnumerator(name: "alpha", value: 0)
81-
!11 = !DIEnumerator(name: "beta", value: 1)
82-
!12 = !DIEnumerator(name: "gamma", value: 2)
83-
!13 = !DIEnumerator(name: "delta", value: 3)
84-
!14 = !DIEnumerator(name: "epsilon", value: 4)
85-
!15 = !DIEnumerator(name: "theta", value: 5)
86-
!16 = !DIEnumerator(name: "psi", value: 6)
87-
!17 = !DIEnumerator(name: "zeta", value: 7)
88-
!18 = !{i64 2, !"Dwarf Version", i64 4}
89-
!19 = !{i64 2, !"Debug Info Version", i64 3}
90-
!20 = !{i64 2, !"wchar_size", i64 2}
91-
!21 = !DILocation(line: 20, scope: !5)
92-
!22 = !DILocalVariable(name: "as", scope: !5, file: !2, line: 11, type: !23)
93-
!23 = !DIDerivedType(tag: DW_TAG_set_type, name: "SS", scope: !2, file: !2, line: 11, baseType: !24, size: 64, align: 64)
94-
!24 = !DIBasicType(name: "SR", size: 8, encoding: DW_ATE_signed)
70+
attributes #0 = { "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
71+
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
72+
73+
!llvm.dbg.cu = !{!0}
74+
!llvm.module.flags = !{!13, !14, !15, !16, !17}
75+
76+
!0 = distinct !DICompileUnit(language: DW_LANG_Modula3, file: !1, producer: "cm3", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
77+
!1 = !DIFile(filename: "Main.m3", directory: "/home/peter/cm3/settest/src")
78+
!2 = !{!3}
79+
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", scope: !1, file: !1, line: 1, size: 8, align: 8, elements: !4)
80+
!4 = !{!5, !6, !7, !8, !9, !10, !11, !12}
81+
!5 = !DIEnumerator(name: "alpha", value: 0)
82+
!6 = !DIEnumerator(name: "beta", value: 1)
83+
!7 = !DIEnumerator(name: "gamma", value: 2)
84+
!8 = !DIEnumerator(name: "delta", value: 3)
85+
!9 = !DIEnumerator(name: "epsilon", value: 4)
86+
!10 = !DIEnumerator(name: "theta", value: 5)
87+
!11 = !DIEnumerator(name: "psi", value: 6)
88+
!12 = !DIEnumerator(name: "zeta", value: 7)
89+
!13 = !{i32 2, !"Dwarf Version", i32 4}
90+
!14 = !{i32 2, !"Debug Info Version", i32 3}
91+
!15 = !{i32 2, !"wchar_size", i32 2}
92+
!16 = !{i32 2, !"PIC Level", i32 2}
93+
!17 = !{i32 2, !"PIE Level", i32 2}
94+
!18 = distinct !DISubprogram(name: "Test", linkageName: "Main__Test", scope: !1, file: !1, line: 18, type: !19, scopeLine: 18, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !21)
95+
!19 = !DISubroutineType(types: !20)
96+
!20 = !{null}
97+
!21 = !{}
98+
!22 = !DILocation(line: 30, scope: !18)
99+
!23 = !DILocalVariable(name: "as", scope: !18, file: !1, line: 19, type: !24)
100+
!24 = !DIDerivedType(tag: DW_TAG_set_type, name: "SS", scope: !1, file: !1, line: 1, baseType: !25, size: 64, align: 64)
95101
; CHECK: DW_TAG_set_type
96102
; CHECK: DW_AT_type{{.*}}"SR"
97103
; CHECK: DW_AT_name ("SS")
98104
; CHECK: DW_AT_byte_size (0x08)
99-
!25 = !DILocation(line: 11, scope: !5)
100-
!26 = !DILocalVariable(name: "bs", scope: !5, file: !2, line: 11, type: !27)
101-
!27 = !DIDerivedType(tag: DW_TAG_set_type, name: "ST", scope: !2, file: !2, line: 11, baseType: !4, size: 64, align: 64)
105+
!25 = !DISubrangeType(name: "SR", scope: !1, file: !1, line: 1, size: 8, align: 8, baseType: !26, lowerBound: i64 0, upperBound: i64 55)
106+
!26 = !DIBasicType(name: "SR_BASE", size: 8, encoding: DW_ATE_signed)
107+
!27 = !DILocation(line: 18, scope: !18)
108+
!28 = !DILocalVariable(name: "bs", scope: !18, file: !1, line: 19, type: !29)
109+
!29 = !DIDerivedType(tag: DW_TAG_set_type, name: "ST", scope: !1, file: !1, line: 1, baseType: !3, size: 8, align: 8)
102110
; CHECK: DW_TAG_set_type
103111
; CHECK: DW_AT_type{{.*}}"Enum"
104112
; CHECK: DW_AT_name ("ST")
105-
; CHECK: DW_AT_byte_size (0x08)
106-
!28 = !DILocation(line: 17, scope: !5)
107-
!29 = !DILocation(line: 18, scope: !5)
108-
!30 = distinct !DISubprogram(name: "Main_M3", linkageName: "Main_M3", scope: !2, file: !2, line: 22, type: !31, scopeLine: 22, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !8)
109-
!31 = !DISubroutineType(types: !32)
110-
!32 = !{!33, !35}
111-
!33 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "ADDR", baseType: !34, size: 64, align: 64)
112-
!34 = !DICompositeType(tag: DW_TAG_class_type, name: "ADDR__HeapObject", scope: !5, file: !2, line: 22, size: 64, align: 64, identifier: "AJWxb1")
113-
!35 = !DIBasicType(name: "INTEGER", size: 64, encoding: DW_ATE_signed)
114-
!36 = !DILocation(line: 23, scope: !30)
115-
!37 = !DILocalVariable(name: "mode", arg: 1, scope: !30, file: !2, line: 22, type: !35)
116-
!38 = !DILocation(line: 22, scope: !30)
113+
; CHECK: DW_AT_byte_size (0x01)
114+
!30 = !DILocalVariable(name: "sc", scope: !18, file: !1, line: 19, type: !31)
115+
!31 = !DIDerivedType(tag: DW_TAG_set_type, name: "SC", scope: !1, file: !1, line: 1, baseType: !32, size: 256, align: 64)
116+
; CHECK: DW_TAG_set_type
117+
; CHECK: DW_AT_type{{.*}}"CHAR"
118+
; CHECK: DW_AT_name ("SC")
119+
; CHECK: DW_AT_byte_size (0x20)
120+
!32 = !DIBasicType(name: "CHAR", size: 8, encoding: DW_ATE_unsigned_char)
121+
!33 = !DILocalVariable(name: "sb", scope: !18, file: !1, line: 19, type: !34)
122+
!34 = !DIDerivedType(tag: DW_TAG_set_type, name: "SB", scope: !1, file: !1, line: 1, baseType: !35, size: 8, align: 8)
123+
!35 = !DIBasicType(name: "BOOLEAN", size: 8, encoding: DW_ATE_boolean)
124+
!36 = !DILocation(line: 25, scope: !18)
125+
!37 = !DILocation(line: 26, scope: !18)
126+
!38 = !DILocation(line: 27, scope: !18)
127+
!39 = !DILocation(line: 28, scope: !18)
128+
!40 = distinct !DISubprogram(name: "Main_M3", linkageName: "Main_M3", scope: !1, file: !1, line: 32, type: !41, scopeLine: 32, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !21)
129+
!41 = !DISubroutineType(types: !42)
130+
!42 = !{!43, !44}
131+
!43 = !DICompositeType(tag: DW_TAG_class_type, name: "ADDR", scope: !1, file: !1, line: 1, size: 64, align: 64, elements: !21, identifier: "AJWxb1")
132+
!44 = !DIBasicType(name: "INTEGER", size: 64, encoding: DW_ATE_signed)
133+
!45 = !DILocation(line: 33, scope: !40)
134+
!46 = !DILocalVariable(name: "mode", arg: 1, scope: !40, file: !1, line: 32, type: !44)
135+
!47 = !DILocation(line: 32, scope: !40)

0 commit comments

Comments
 (0)