llvm.org GIT mirror llvm / d33fc8b
Store a pointer to the return value in a static alloca and let the debugger use that as the variable address for NRVO variables. Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D63361 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363952 91177308-0d34-0410-b5e6-96231b3b80d8 Amy Huang 28 days ago
2 changed file(s) with 156 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11411141 // If the variable has an attached offset expression, extract it.
11421142 // FIXME: Try to handle DW_OP_deref as well.
11431143 int64_t ExprOffset = 0;
1144 if (VI.Expr)
1145 if (!VI.Expr->extractIfOffset(ExprOffset))
1144 bool Deref = false;
1145 if (VI.Expr) {
1146 // If there is one DW_OP_deref element, use offset of 0 and keep going.
1147 if (VI.Expr->getNumElements() == 1 &&
1148 VI.Expr->getElement(0) == llvm::dwarf::DW_OP_deref)
1149 Deref = true;
1150 else if (!VI.Expr->extractIfOffset(ExprOffset))
11461151 continue;
1152 }
11471153
11481154 // Get the frame register used and the offset.
11491155 unsigned FrameReg = 0;
11531159 // Calculate the label ranges.
11541160 LocalVarDefRange DefRange =
11551161 createDefRangeMem(CVReg, FrameOffset + ExprOffset);
1162
11561163 for (const InsnRange &Range : Scope->getRanges()) {
11571164 const MCSymbol *Begin = getLabelBeforeInsn(Range.first);
11581165 const MCSymbol *End = getLabelAfterInsn(Range.second);
11631170 LocalVariable Var;
11641171 Var.DIVar = VI.Var;
11651172 Var.DefRanges.emplace_back(std::move(DefRange));
1173 if (Deref)
1174 Var.UseReferenceType = true;
1175
11661176 recordLocalVariable(std::move(Var), Scope);
11671177 }
11681178 }
0 ; RUN: llc < %s | FileCheck %s --check-prefix=ASM
1 ; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ
2
3 ; C++ source to regenerate:
4 ; struct Foo {
5 ; Foo() = default;
6 ; Foo(Foo &&other) { x = other.x; }
7 ; int x;
8 ; };
9 ; void some_function(int);
10 ; Foo getFoo() {
11 ; Foo foo;
12 ; foo.x = 41;
13 ; some_function(foo.x);
14 ; return foo;
15 ; }
16 ;
17 ; int main() {
18 ; Foo bar = getFoo();
19 ; return bar.x;
20 ; }
21 ; $ clang t.cpp -S -emit-llvm -g -o t.ll
22
23 ; ASM-LABEL: .long 241 # Symbol subsection for GetFoo
24 ; ASM: .short 4414 # Record kind: S_LOCAL
25 ; ASM-NEXT: .long 4113 # TypeIndex
26 ; ASM-NEXT: .short 0 # Flags
27 ; ASM-NEXT: .asciz "foo"
28 ; ASM-NEXT: .p2align 2
29 ; ASM-NEXT: .Ltmp
30 ; ASM: .cv_def_range .Ltmp{{.*}} .Ltmp{{.*}}, "B\021(\000\000\000"
31
32 ; OBJ: Subsection [
33 ; OBJ: SubSectionType: Symbols (0xF1)
34 ; OBJ: LocalSym {
35 ; OBJ: Kind: S_LOCAL (0x113E)
36 ; OBJ: Type: Foo& (0x1011)
37 ; OBJ: Flags [ (0x0)
38 ; OBJ: ]
39 ; OBJ: VarName: foo
40 ; OBJ: }
41 ; OBJ: DefRangeFramePointerRelSym {
42 ; OBJ: Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
43 ; OBJ: Offset: 40
44 ; OBJ: LocalVariableAddrRange {
45 ; OBJ: OffsetStart: .text+0x1D
46 ; OBJ: ISectStart: 0x0
47 ; OBJ: Range: 0x16
48 ; OBJ: }
49
50 ; ModuleID = 't.cpp'
51 source_filename = "t.cpp"
52 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
53 target triple = "x86_64-pc-windows-msvc19.16.27030"
54
55 %struct.Foo = type { i32 }
56
57 ; Function Attrs: noinline nounwind optnone uwtable
58 define dso_local void @"?some_function@@YAXH@Z"(i32) #0 !dbg !8 {
59 entry:
60 %.addr = alloca i32, align 4
61 store i32 %0, i32* %.addr, align 4
62 call void @llvm.dbg.declare(metadata i32* %.addr, metadata !12, metadata !DIExpression()), !dbg !13
63 ret void, !dbg !13
64 }
65
66 ; Function Attrs: nounwind readnone speculatable
67 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
68
69 ; Function Attrs: noinline nounwind optnone uwtable
70 define dso_local void @"?GetFoo@@YA?AUFoo@@XZ"(%struct.Foo* noalias sret %agg.result) #0 !dbg !14 {
71 entry:
72 %result.ptr = alloca i8*, align 8
73 %0 = bitcast %struct.Foo* %agg.result to i8*
74 store i8* %0, i8** %result.ptr, align 8
75 call void @llvm.dbg.declare(metadata i8** %result.ptr, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !29
76 %x = getelementptr inbounds %struct.Foo, %struct.Foo* %agg.result, i32 0, i32 0, !dbg !30
77 store i32 41, i32* %x, align 4, !dbg !30
78 %x1 = getelementptr inbounds %struct.Foo, %struct.Foo* %agg.result, i32 0, i32 0, !dbg !31
79 %1 = load i32, i32* %x1, align 4, !dbg !31
80 call void @"?some_function@@YAXH@Z"(i32 %1), !dbg !31
81 ret void, !dbg !32
82 }
83
84 ; Function Attrs: noinline norecurse nounwind optnone uwtable
85 define dso_local i32 @main() #2 !dbg !33 {
86 entry:
87 %retval = alloca i32, align 4
88 %bar = alloca %struct.Foo, align 4
89 store i32 0, i32* %retval, align 4
90 call void @llvm.dbg.declare(metadata %struct.Foo* %bar, metadata !36, metadata !DIExpression()), !dbg !37
91 call void @"?GetFoo@@YA?AUFoo@@XZ"(%struct.Foo* sret %bar), !dbg !37
92 %x = getelementptr inbounds %struct.Foo, %struct.Foo* %bar, i32 0, i32 0, !dbg !38
93 %0 = load i32, i32* %x, align 4, !dbg !38
94 ret i32 %0, !dbg !38
95 }
96
97 attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
98 attributes #1 = { nounwind readnone speculatable }
99 attributes #2 = { noinline norecurse nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
100
101 !llvm.dbg.cu = !{!0}
102 !llvm.module.flags = !{!3, !4, !5, !6}
103 !llvm.ident = !{!7}
104
105 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git c19ebebac4bf853e77a69c74abe9f7fce98c1d17)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
106 !1 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Ctesting\5Cnrvo", checksumkind: CSK_MD5, checksum: "52a5a20c02c102dfd255d5615680a8bd")
107 !2 = !{}
108 !3 = !{i32 2, !"CodeView", i32 1}
109 !4 = !{i32 2, !"Debug Info Version", i32 3}
110 !5 = !{i32 1, !"wchar_size", i32 2}
111 !6 = !{i32 7, !"PIC Level", i32 2}
112 !7 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git c19ebebac4bf853e77a69c74abe9f7fce98c1d17)"}
113 !8 = distinct !DISubprogram(name: "some_function", linkageName: "?some_function@@YAXH@Z", scope: !1, file: !1, line: 13, type: !9, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
114 !9 = !DISubroutineType(types: !10)
115 !10 = !{null, !11}
116 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
117 !12 = !DILocalVariable(arg: 1, scope: !8, file: !1, line: 13, type: !11)
118 !13 = !DILocation(line: 13, scope: !8)
119 !14 = distinct !DISubprogram(name: "GetFoo", linkageName: "?GetFoo@@YA?AUFoo@@XZ", scope: !1, file: !1, line: 15, type: !15, scopeLine: 15, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
120 !15 = !DISubroutineType(types: !16)
121 !16 = !{!17}
122 !17 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 32, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !18, identifier: ".?AUFoo@@")
123 !18 = !{!19, !20, !24}
124 !19 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !17, file: !1, line: 4, baseType: !11, size: 32)
125 !20 = !DISubprogram(name: "Foo", scope: !17, file: !1, line: 2, type: !21, scopeLine: 2, flags: DIFlagPrototyped, spFlags: 0)
126 !21 = !DISubroutineType(types: !22)
127 !22 = !{null, !23}
128 !23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
129 !24 = !DISubprogram(name: "Foo", scope: !17, file: !1, line: 3, type: !25, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)
130 !25 = !DISubroutineType(types: !26)
131 !26 = !{null, !23, !27}
132 !27 = !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: !17, size: 64)
133 !28 = !DILocalVariable(name: "foo", scope: !14, file: !1, line: 17, type: !17)
134 !29 = !DILocation(line: 17, scope: !14)
135 !30 = !DILocation(line: 18, scope: !14)
136 !31 = !DILocation(line: 19, scope: !14)
137 !32 = !DILocation(line: 21, scope: !14)
138 !33 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 23, type: !34, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
139 !34 = !DISubroutineType(types: !35)
140 !35 = !{!11}
141 !36 = !DILocalVariable(name: "bar", scope: !33, file: !1, line: 24, type: !17)
142 !37 = !DILocation(line: 24, scope: !33)
143 !38 = !DILocation(line: 25, scope: !33)