Skip to content

Commit a8c4450

Browse files
authored
Made the this variable in templated struct member functions references (microsoft#6296)
Made the debug info type for the `this` argument a reference type. `DxilRewriteOutputArgDebugInfo` then turns the reference type into a value type to preserve the value mapping when the alloca that `this` points to becomes registers.
1 parent bda8121 commit a8c4450

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

tools/clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,16 +1128,9 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
11281128
// "this" pointer is always first argument.
11291129
const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
11301130
if (isa<ClassTemplateSpecializationDecl>(RD)) {
1131-
// Create pointer type directly in this case.
11321131
// HLSL Change Begin - This is a reference.
1133-
QualType PointeeTy = ThisPtr->getPointeeType();
1134-
unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
1135-
uint64_t Size = CGM.getTarget().getPointerWidth(AS);
1136-
uint64_t Align = CGM.getContext().getTypeAlign(ThisPtr.getTypePtr());
1132+
llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
11371133
// HLSL Change End - This is a reference.
1138-
llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
1139-
llvm::DIType *ThisPtrType =
1140-
DBuilder.createPointerType(PointeeType, Size, Align);
11411134
TypeCache[ThisPtr.getAsOpaquePtr()].reset(ThisPtrType);
11421135
// TODO: This and the artificial type below are misleading, the
11431136
// types aren't artificial the argument is, but the current
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %dxc -E main -T ps_6_0 %s -Zi -O0 | FileCheck %s
2+
// RUN: %dxc -E main -T ps_6_0 %s -Zi -O3 | FileCheck %s
3+
4+
// We check that the broken down elements directly point to the value of the struct S
5+
6+
// CHECK: dbg.value(metadata float %{{.+}}, i64 0, metadata ![[this:.+]], metadata !{{[0-9]+}}), !dbg !{{[0-9]+}} ; var:"this" !DIExpression(DW_OP_bit_piece, 0, 32)
7+
// CHECK: dbg.value(metadata float %{{.+}}, i64 0, metadata ![[this]], metadata !{{[0-9]+}}), !dbg !{{[0-9]+}} ; var:"this" !DIExpression(DW_OP_bit_piece, 32, 32)
8+
// CHECK-DAG: ![[this]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: !{{[0-9]+}}, type: ![[type:[0-9]+]])
9+
// CHECK-DAG: ![[type]] = !DICompositeType(tag: DW_TAG_structure_type, name: "S<float>", file: !{{[0-9]+}}, line: {{[0-9]+}}, size: 64, align: 32, elements: !{{[0-9]+}}, templateParams: !{{[0-9]+}})
10+
11+
template<typename T>
12+
struct S {
13+
T a, b;
14+
T Get() {
15+
return a + b;
16+
}
17+
};
18+
19+
[RootSignature("")]
20+
float main(float x : X, float y : Y, float z : Z, float w : W) : SV_Target {
21+
S<float> s;
22+
s.a = x;
23+
s.b = y;
24+
return s.Get();
25+
}
26+
27+

tools/clang/test/HLSLFileCheck/hlsl/template/templateStructFunc.hlsl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ float2 main(float4 a:A) : SV_Target {
6767
// DI-DAG: [[DITestV:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Test<vector<float, 2> >", file: [[DIFile]], line: {{[0-9]+}}, size: 64, align: 32
6868

6969
// DI-DAG: [[t1FVar]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "t1", arg: 2, scope: [[FSub]], file: [[DIFile]], line: {{[0-9]+}}, type: [[DIFloat]])
70-
// DI-DAG: [[thisFVar]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: [[FSub]], type: [[thisFPtr:![0-9]+]])
71-
// DI-DAG: [[thisFPtr]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[DITestF]], size: 32, align: 32)
70+
// DI-DAG: [[thisFVar]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: [[FSub]], type: [[DITestF]])
7271

7372
// DI-DAG: [[t1VVar]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "t1", arg: 2, scope: [[VSub]], file: [[DIFile]]
74-
// DI-DAG: [[thisVVar]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: [[VSub]], type: [[thisVPtr:![0-9]+]])
75-
// DI-DAG: [[thisVPtr]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[DITestV]], size: 32, align: 32)
73+
// DI-DAG: [[thisVVar]] = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: [[VSub]], type: [[DITestV]])

0 commit comments

Comments
 (0)