Skip to content

Commit 7fac5c8

Browse files
committedJun 20, 2019
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 llvm-svn: 363952
1 parent 0151119 commit 7fac5c8

File tree

14 files changed

+306
-23
lines changed

14 files changed

+306
-23
lines changed
 

‎clang/lib/CodeGen/CGDebugInfo.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,8 @@ CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
38353835
llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
38363836
llvm::Value *Storage,
38373837
llvm::Optional<unsigned> ArgNo,
3838-
CGBuilderTy &Builder) {
3838+
CGBuilderTy &Builder,
3839+
const bool UsePointerValue) {
38393840
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
38403841
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
38413842
if (VD->hasAttr<NoDebugAttr>())
@@ -3940,6 +3941,16 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
39403941
}
39413942
}
39423943

3944+
// Clang stores the sret pointer provided by the caller in a static alloca.
3945+
// Use DW_OP_deref to tell the debugger to load the pointer and treat it as
3946+
// the address of the variable.
3947+
if (UsePointerValue) {
3948+
assert(std::find(Expr.begin(), Expr.end(), llvm::dwarf::DW_OP_deref) ==
3949+
Expr.end() &&
3950+
"Debug info already contains DW_OP_deref.");
3951+
Expr.push_back(llvm::dwarf::DW_OP_deref);
3952+
}
3953+
39433954
// Create the descriptor for the variable.
39443955
auto *D = ArgNo ? DBuilder.createParameterVariable(
39453956
Scope, Name, *ArgNo, Unit, Line, Ty,
@@ -3958,9 +3969,10 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
39583969

39593970
llvm::DILocalVariable *
39603971
CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, llvm::Value *Storage,
3961-
CGBuilderTy &Builder) {
3972+
CGBuilderTy &Builder,
3973+
const bool UsePointerValue) {
39623974
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
3963-
return EmitDeclare(VD, Storage, llvm::None, Builder);
3975+
return EmitDeclare(VD, Storage, llvm::None, Builder, UsePointerValue);
39643976
}
39653977

39663978
void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {

‎clang/lib/CodeGen/CGDebugInfo.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,10 @@ class CGDebugInfo {
422422
/// declaration.
423423
/// Returns a pointer to the DILocalVariable associated with the
424424
/// llvm.dbg.declare, or nullptr otherwise.
425-
llvm::DILocalVariable *EmitDeclareOfAutoVariable(const VarDecl *Decl,
426-
llvm::Value *AI,
427-
CGBuilderTy &Builder);
425+
llvm::DILocalVariable *
426+
EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
427+
CGBuilderTy &Builder,
428+
const bool UsePointerValue = false);
428429

429430
/// Emit call to \c llvm.dbg.label for an label.
430431
void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder);
@@ -507,7 +508,8 @@ class CGDebugInfo {
507508
/// llvm.dbg.declare, or nullptr otherwise.
508509
llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
509510
llvm::Optional<unsigned> ArgNo,
510-
CGBuilderTy &Builder);
511+
CGBuilderTy &Builder,
512+
const bool UsePointerValue = false);
511513

512514
struct BlockByRefType {
513515
/// The wrapper struct used inside the __block_literal struct.

‎clang/lib/CodeGen/CGDecl.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -1403,12 +1403,11 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
14031403
getLangOpts().OpenMP
14041404
? CGM.getOpenMPRuntime().getAddressOfLocalVariable(*this, &D)
14051405
: Address::invalid();
1406+
bool NRVO = getLangOpts().ElideConstructors && D.isNRVOVariable();
1407+
14061408
if (getLangOpts().OpenMP && OpenMPLocalAddr.isValid()) {
14071409
address = OpenMPLocalAddr;
14081410
} else if (Ty->isConstantSizeType()) {
1409-
bool NRVO = getLangOpts().ElideConstructors &&
1410-
D.isNRVOVariable();
1411-
14121411
// If this value is an array or struct with a statically determinable
14131412
// constant initializer, there are optimizations we can do.
14141413
//
@@ -1561,8 +1560,16 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
15611560

15621561
// Emit debug info for local var declaration.
15631562
if (EmitDebugInfo && HaveInsertPoint()) {
1563+
Address DebugAddr = address;
1564+
bool UsePointerValue = NRVO && ReturnValuePointer.isValid();
15641565
DI->setLocation(D.getLocation());
1565-
(void)DI->EmitDeclareOfAutoVariable(&D, address.getPointer(), Builder);
1566+
1567+
// If NRVO, use a pointer to the return address.
1568+
if (UsePointerValue)
1569+
DebugAddr = ReturnValuePointer;
1570+
1571+
(void)DI->EmitDeclareOfAutoVariable(&D, DebugAddr.getPointer(), Builder,
1572+
UsePointerValue);
15661573
}
15671574

15681575
if (D.hasAttr<AnnotateAttr>() && HaveInsertPoint())

‎clang/lib/CodeGen/CodeGenFunction.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,21 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
895895
if (CurFnInfo->getReturnInfo().isSRetAfterThis())
896896
++AI;
897897
ReturnValue = Address(&*AI, CurFnInfo->getReturnInfo().getIndirectAlign());
898+
if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
899+
ReturnValuePointer =
900+
CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
901+
Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
902+
ReturnValue.getPointer(), Int8PtrTy),
903+
ReturnValuePointer);
904+
}
898905
} else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
899906
!hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
900907
// Load the sret pointer from the argument struct and return into that.
901908
unsigned Idx = CurFnInfo->getReturnInfo().getInAllocaFieldIndex();
902909
llvm::Function::arg_iterator EI = CurFn->arg_end();
903910
--EI;
904911
llvm::Value *Addr = Builder.CreateStructGEP(nullptr, &*EI, Idx);
912+
ReturnValuePointer = Address(Addr, getPointerAlign());
905913
Addr = Builder.CreateAlignedLoad(Addr, getPointerAlign(), "agg.result");
906914
ReturnValue = Address(Addr, getNaturalTypeAlignment(RetTy));
907915
} else {

‎clang/lib/CodeGen/CodeGenFunction.h

+4
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ class CodeGenFunction : public CodeGenTypeCache {
327327
/// value. This is invalid iff the function has no return value.
328328
Address ReturnValue = Address::invalid();
329329

330+
/// ReturnValuePointer - The temporary alloca to hold a pointer to sret.
331+
/// This is invalid if sret is not in use.
332+
Address ReturnValuePointer = Address::invalid();
333+
330334
/// Return true if a label was seen in the current scope.
331335
bool hasLabelBeenSeenInCurrentScope() const {
332336
if (CurLexicalScope)

‎clang/test/CodeGen/arm64-microsoft-arguments.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ S3 f3() {
4343
// Pass and return aggregate (of size < 16 bytes) with non-trivial destructor.
4444
// Passed directly but returned indirectly.
4545
// CHECK: define {{.*}} void {{.*}}f4{{.*}}(%struct.S4* inreg noalias sret %agg.result)
46-
// CHECK: call void {{.*}}func4{{.*}}(%struct.S4* inreg sret %agg.result, [2 x i64] %4)
46+
// CHECK: call void {{.*}}func4{{.*}}(%struct.S4* inreg sret %agg.result, [2 x i64] %5)
4747
struct S4 {
4848
int a[3];
4949
~S4();
@@ -57,7 +57,7 @@ S4 f4() {
5757

5858
// Pass and return from instance method called from instance method.
5959
// CHECK: define {{.*}} void @{{.*}}bar@Q1{{.*}}(%class.Q1* %this, %class.P1* inreg noalias sret %agg.result)
60-
// CHECK: call void {{.*}}foo@P1{{.*}}(%class.P1* %ref.tmp, %class.P1* inreg sret %agg.result, i8 %0)
60+
// CHECK: call void {{.*}}foo@P1{{.*}}(%class.P1* %ref.tmp, %class.P1* inreg sret %agg.result, i8 %1)
6161

6262
class P1 {
6363
public:

‎clang/test/CodeGenCXX/conditional-gnu-ext.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace test3 {
7979
B test0(B &x) {
8080
// CHECK-LABEL: define void @_ZN5test35test0ERNS_1BE(
8181
// CHECK: [[X:%.*]] = alloca [[B:%.*]]*,
82-
// CHECK-NEXT: store [[B]]* {{%.*}}, [[B]]** [[X]]
82+
// CHECK: store [[B]]* {{%.*}}, [[B]]** [[X]]
8383
// CHECK-NEXT: [[T0:%.*]] = load [[B]]*, [[B]]** [[X]]
8484
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[T0]])
8585
// CHECK-NEXT: br i1 [[BOOL]]
@@ -94,7 +94,7 @@ namespace test3 {
9494
B test1() {
9595
// CHECK-LABEL: define void @_ZN5test35test1Ev(
9696
// CHECK: [[TEMP:%.*]] = alloca [[B]],
97-
// CHECK-NEXT: call void @_ZN5test312test1_helperEv([[B]]* sret [[TEMP]])
97+
// CHECK: call void @_ZN5test312test1_helperEv([[B]]* sret [[TEMP]])
9898
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[TEMP]])
9999
// CHECK-NEXT: br i1 [[BOOL]]
100100
// CHECK: call void @_ZN5test31BC1ERKS0_([[B]]* [[RESULT:%.*]], [[B]]* dereferenceable({{[0-9]+}}) [[TEMP]])
@@ -111,7 +111,7 @@ namespace test3 {
111111
A test2(B &x) {
112112
// CHECK-LABEL: define void @_ZN5test35test2ERNS_1BE(
113113
// CHECK: [[X:%.*]] = alloca [[B]]*,
114-
// CHECK-NEXT: store [[B]]* {{%.*}}, [[B]]** [[X]]
114+
// CHECK: store [[B]]* {{%.*}}, [[B]]** [[X]]
115115
// CHECK-NEXT: [[T0:%.*]] = load [[B]]*, [[B]]** [[X]]
116116
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[T0]])
117117
// CHECK-NEXT: br i1 [[BOOL]]
@@ -126,7 +126,7 @@ namespace test3 {
126126
A test3() {
127127
// CHECK-LABEL: define void @_ZN5test35test3Ev(
128128
// CHECK: [[TEMP:%.*]] = alloca [[B]],
129-
// CHECK-NEXT: call void @_ZN5test312test3_helperEv([[B]]* sret [[TEMP]])
129+
// CHECK: call void @_ZN5test312test3_helperEv([[B]]* sret [[TEMP]])
130130
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[TEMP]])
131131
// CHECK-NEXT: br i1 [[BOOL]]
132132
// CHECK: call void @_ZN5test31BcvNS_1AEEv([[A]]* sret [[RESULT:%.*]], [[B]]* [[TEMP]])
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s
2+
// RUN: %clangxx -target x86_64-unknown-unknown -g -fno-elide-constructors %s -emit-llvm -S -o - | FileCheck %s -check-prefix=NOELIDE
3+
struct Foo {
4+
Foo() = default;
5+
Foo(Foo &&other) { x = other.x; }
6+
int x;
7+
};
8+
void some_function(int);
9+
Foo getFoo() {
10+
Foo foo;
11+
foo.x = 41;
12+
some_function(foo.x);
13+
return foo;
14+
}
15+
16+
int main() {
17+
Foo bar = getFoo();
18+
return bar.x;
19+
}
20+
21+
// Check that NRVO variables are stored as a pointer with deref if they are
22+
// stored in the return register.
23+
24+
// CHECK: %result.ptr = alloca i8*, align 8
25+
// CHECK: call void @llvm.dbg.declare(metadata i8** %result.ptr,
26+
// CHECK-SAME: metadata !DIExpression(DW_OP_deref)
27+
// NOELIDE: call void @llvm.dbg.declare(metadata %struct.Foo* %foo,
28+
// NOELIDE-SAME: metadata !DIExpression()

‎clang/test/CodeGenCXX/lambda-expressions.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ namespace pr28595 {
195195
// CHECK-NEXT: ret i32
196196

197197
// CHECK-LABEL: define internal void @"_ZZ1hvEN4$_118__invokeEv"(%struct.A* noalias sret %agg.result) {{.*}} {
198-
// CHECK-NOT: =
199198
// CHECK: call void @"_ZZ1hvENK4$_11clEv"(%struct.A* sret %agg.result,
200199
// CHECK-NEXT: ret void
201200
struct A { ~A(); };

‎clang/test/CodeGenObjC/objc-non-trivial-struct-nrvo.m

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Trivial testTrivial(void) {
3838
void func1(TrivialBig *);
3939

4040
// CHECK: define void @testTrivialBig(%[[STRUCT_TRIVIALBIG]]* noalias sret %[[AGG_RESULT:.*]])
41-
// CHECK-NOT: alloca
4241
// CHECK: call void @func1(%[[STRUCT_TRIVIALBIG]]* %[[AGG_RESULT]])
4342
// CHECK-NEXT: ret void
4443

‎debuginfo-tests/nrvo-string.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,32 @@ struct string {
1717
string get_string() {
1818
string unused;
1919
string result = 3;
20-
// DEBUGGER: break 21
20+
// DEBUGGER: break 21
2121
return result;
2222
}
23-
int main() { get_string(); }
23+
void some_function(int) {}
24+
struct string2 {
25+
string2() = default;
26+
string2(string2 &&other) { i = other.i; }
27+
int i;
28+
};
29+
string2 get_string2() {
30+
string2 result;
31+
result.i = 5;
32+
some_function(result.i);
33+
// Test that the debugger can get the value of result after another
34+
// function is called.
35+
// DEBUGGER: break 35
36+
return result;
37+
}
38+
int main() {
39+
get_string();
40+
get_string2();
41+
}
2442

2543
// DEBUGGER: r
2644
// DEBUGGER: print result.i
2745
// CHECK: = 3
46+
// DEBUGGER: c
47+
// DEBUGGER: print result.i
48+
// CHECK: = 5

‎debuginfo-tests/win_cdb/nrvo.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This ensures that DW_OP_deref is inserted when necessary, such as when NRVO
2+
// of a string object occurs in C++.
3+
//
4+
// RUN: %clang_cl %s -o %t.exe -fuse-ld=lld -Z7
5+
// RUN: grep DE[B]UGGER: %s | sed -e 's/.*DE[B]UGGER: //' > %t.script
6+
// RUN: %cdb -cf %t.script %t.exe | FileCheck %s --check-prefixes=DEBUGGER,CHECK
7+
//
8+
9+
struct string {
10+
string() {}
11+
string(int i) : i(i) {}
12+
~string() {}
13+
int i = 0;
14+
};
15+
string get_string() {
16+
string unused;
17+
string result = 3;
18+
__debugbreak();
19+
return result;
20+
}
21+
void some_function(int) {}
22+
struct string2 {
23+
string2() = default;
24+
string2(string2 &&other) { i = other.i; }
25+
int i;
26+
};
27+
string2 get_string2() {
28+
string2 result;
29+
result.i = 5;
30+
some_function(result.i);
31+
// Test that the debugger can get the value of result after another
32+
// function is called.
33+
__debugbreak();
34+
return result;
35+
}
36+
int main() {
37+
get_string();
38+
get_string2();
39+
}
40+
41+
// DEBUGGER: g
42+
// DEBUGGER: ?? result
43+
// CHECK: struct string *
44+
// CHECK: +0x000 i : 0n3
45+
// DEBUGGER: g
46+
// DEBUGGER: ?? result
47+
// CHECK: struct string2 *
48+
// CHECK: +0x000 i : 0n5
49+
// DEBUGGER: q

‎llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,15 @@ void CodeViewDebug::collectVariableInfoFromMFTable(
11421142
// If the variable has an attached offset expression, extract it.
11431143
// FIXME: Try to handle DW_OP_deref as well.
11441144
int64_t ExprOffset = 0;
1145-
if (VI.Expr)
1146-
if (!VI.Expr->extractIfOffset(ExprOffset))
1145+
bool Deref = false;
1146+
if (VI.Expr) {
1147+
// If there is one DW_OP_deref element, use offset of 0 and keep going.
1148+
if (VI.Expr->getNumElements() == 1 &&
1149+
VI.Expr->getElement(0) == llvm::dwarf::DW_OP_deref)
1150+
Deref = true;
1151+
else if (!VI.Expr->extractIfOffset(ExprOffset))
11471152
continue;
1153+
}
11481154

11491155
// Get the frame register used and the offset.
11501156
unsigned FrameReg = 0;
@@ -1154,6 +1160,7 @@ void CodeViewDebug::collectVariableInfoFromMFTable(
11541160
// Calculate the label ranges.
11551161
LocalVarDefRange DefRange =
11561162
createDefRangeMem(CVReg, FrameOffset + ExprOffset);
1163+
11571164
for (const InsnRange &Range : Scope->getRanges()) {
11581165
const MCSymbol *Begin = getLabelBeforeInsn(Range.first);
11591166
const MCSymbol *End = getLabelAfterInsn(Range.second);
@@ -1164,6 +1171,9 @@ void CodeViewDebug::collectVariableInfoFromMFTable(
11641171
LocalVariable Var;
11651172
Var.DIVar = VI.Var;
11661173
Var.DefRanges.emplace_back(std::move(DefRange));
1174+
if (Deref)
1175+
Var.UseReferenceType = true;
1176+
11671177
recordLocalVariable(std::move(Var), Scope);
11681178
}
11691179
}

‎llvm/test/DebugInfo/COFF/nrvo.ll

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
; RUN: llc < %s | FileCheck %s --check-prefix=ASM
2+
; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ
3+
4+
; C++ source to regenerate:
5+
; struct Foo {
6+
; Foo() = default;
7+
; Foo(Foo &&other) { x = other.x; }
8+
; int x;
9+
; };
10+
; void some_function(int);
11+
; Foo getFoo() {
12+
; Foo foo;
13+
; foo.x = 41;
14+
; some_function(foo.x);
15+
; return foo;
16+
; }
17+
;
18+
; int main() {
19+
; Foo bar = getFoo();
20+
; return bar.x;
21+
; }
22+
; $ clang t.cpp -S -emit-llvm -g -o t.ll
23+
24+
; ASM-LABEL: .long 241 # Symbol subsection for GetFoo
25+
; ASM: .short 4414 # Record kind: S_LOCAL
26+
; ASM-NEXT: .long 4113 # TypeIndex
27+
; ASM-NEXT: .short 0 # Flags
28+
; ASM-NEXT: .asciz "foo"
29+
; ASM-NEXT: .p2align 2
30+
; ASM-NEXT: .Ltmp
31+
; ASM: .cv_def_range .Ltmp{{.*}} .Ltmp{{.*}}, "B\021(\000\000\000"
32+
33+
; OBJ: Subsection [
34+
; OBJ: SubSectionType: Symbols (0xF1)
35+
; OBJ: LocalSym {
36+
; OBJ: Kind: S_LOCAL (0x113E)
37+
; OBJ: Type: Foo& (0x1011)
38+
; OBJ: Flags [ (0x0)
39+
; OBJ: ]
40+
; OBJ: VarName: foo
41+
; OBJ: }
42+
; OBJ: DefRangeFramePointerRelSym {
43+
; OBJ: Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
44+
; OBJ: Offset: 40
45+
; OBJ: LocalVariableAddrRange {
46+
; OBJ: OffsetStart: .text+0x1D
47+
; OBJ: ISectStart: 0x0
48+
; OBJ: Range: 0x16
49+
; OBJ: }
50+
51+
; ModuleID = 't.cpp'
52+
source_filename = "t.cpp"
53+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
54+
target triple = "x86_64-pc-windows-msvc19.16.27030"
55+
56+
%struct.Foo = type { i32 }
57+
58+
; Function Attrs: noinline nounwind optnone uwtable
59+
define dso_local void @"?some_function@@YAXH@Z"(i32) #0 !dbg !8 {
60+
entry:
61+
%.addr = alloca i32, align 4
62+
store i32 %0, i32* %.addr, align 4
63+
call void @llvm.dbg.declare(metadata i32* %.addr, metadata !12, metadata !DIExpression()), !dbg !13
64+
ret void, !dbg !13
65+
}
66+
67+
; Function Attrs: nounwind readnone speculatable
68+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
69+
70+
; Function Attrs: noinline nounwind optnone uwtable
71+
define dso_local void @"?GetFoo@@YA?AUFoo@@XZ"(%struct.Foo* noalias sret %agg.result) #0 !dbg !14 {
72+
entry:
73+
%result.ptr = alloca i8*, align 8
74+
%0 = bitcast %struct.Foo* %agg.result to i8*
75+
store i8* %0, i8** %result.ptr, align 8
76+
call void @llvm.dbg.declare(metadata i8** %result.ptr, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !29
77+
%x = getelementptr inbounds %struct.Foo, %struct.Foo* %agg.result, i32 0, i32 0, !dbg !30
78+
store i32 41, i32* %x, align 4, !dbg !30
79+
%x1 = getelementptr inbounds %struct.Foo, %struct.Foo* %agg.result, i32 0, i32 0, !dbg !31
80+
%1 = load i32, i32* %x1, align 4, !dbg !31
81+
call void @"?some_function@@YAXH@Z"(i32 %1), !dbg !31
82+
ret void, !dbg !32
83+
}
84+
85+
; Function Attrs: noinline norecurse nounwind optnone uwtable
86+
define dso_local i32 @main() #2 !dbg !33 {
87+
entry:
88+
%retval = alloca i32, align 4
89+
%bar = alloca %struct.Foo, align 4
90+
store i32 0, i32* %retval, align 4
91+
call void @llvm.dbg.declare(metadata %struct.Foo* %bar, metadata !36, metadata !DIExpression()), !dbg !37
92+
call void @"?GetFoo@@YA?AUFoo@@XZ"(%struct.Foo* sret %bar), !dbg !37
93+
%x = getelementptr inbounds %struct.Foo, %struct.Foo* %bar, i32 0, i32 0, !dbg !38
94+
%0 = load i32, i32* %x, align 4, !dbg !38
95+
ret i32 %0, !dbg !38
96+
}
97+
98+
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" }
99+
attributes #1 = { nounwind readnone speculatable }
100+
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" }
101+
102+
!llvm.dbg.cu = !{!0}
103+
!llvm.module.flags = !{!3, !4, !5, !6}
104+
!llvm.ident = !{!7}
105+
106+
!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)
107+
!1 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Ctesting\5Cnrvo", checksumkind: CSK_MD5, checksum: "52a5a20c02c102dfd255d5615680a8bd")
108+
!2 = !{}
109+
!3 = !{i32 2, !"CodeView", i32 1}
110+
!4 = !{i32 2, !"Debug Info Version", i32 3}
111+
!5 = !{i32 1, !"wchar_size", i32 2}
112+
!6 = !{i32 7, !"PIC Level", i32 2}
113+
!7 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git c19ebebac4bf853e77a69c74abe9f7fce98c1d17)"}
114+
!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)
115+
!9 = !DISubroutineType(types: !10)
116+
!10 = !{null, !11}
117+
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
118+
!12 = !DILocalVariable(arg: 1, scope: !8, file: !1, line: 13, type: !11)
119+
!13 = !DILocation(line: 13, scope: !8)
120+
!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)
121+
!15 = !DISubroutineType(types: !16)
122+
!16 = !{!17}
123+
!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 32, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !18, identifier: ".?AUFoo@@")
124+
!18 = !{!19, !20, !24}
125+
!19 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !17, file: !1, line: 4, baseType: !11, size: 32)
126+
!20 = !DISubprogram(name: "Foo", scope: !17, file: !1, line: 2, type: !21, scopeLine: 2, flags: DIFlagPrototyped, spFlags: 0)
127+
!21 = !DISubroutineType(types: !22)
128+
!22 = !{null, !23}
129+
!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
130+
!24 = !DISubprogram(name: "Foo", scope: !17, file: !1, line: 3, type: !25, scopeLine: 3, flags: DIFlagPrototyped, spFlags: 0)
131+
!25 = !DISubroutineType(types: !26)
132+
!26 = !{null, !23, !27}
133+
!27 = !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: !17, size: 64)
134+
!28 = !DILocalVariable(name: "foo", scope: !14, file: !1, line: 17, type: !17)
135+
!29 = !DILocation(line: 17, scope: !14)
136+
!30 = !DILocation(line: 18, scope: !14)
137+
!31 = !DILocation(line: 19, scope: !14)
138+
!32 = !DILocation(line: 21, scope: !14)
139+
!33 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 23, type: !34, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
140+
!34 = !DISubroutineType(types: !35)
141+
!35 = !{!11}
142+
!36 = !DILocalVariable(name: "bar", scope: !33, file: !1, line: 24, type: !17)
143+
!37 = !DILocation(line: 24, scope: !33)
144+
!38 = !DILocation(line: 25, scope: !33)

0 commit comments

Comments
 (0)
Please sign in to comment.