xref: /llvm-project/clang/test/CodeGenHLSL/this-reference.hlsl (revision 762f1b17b2815ccdfb4e5cb5412cb6210db92f73)
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s -debug-info-kind=standalone -dwarf-version=4 | FileCheck %s
2
3struct Pair {
4  int First;
5  float Second;
6
7  int getFirst() {
8	  return this.First;
9  }
10
11  float getSecond() {
12    return Second;
13  }
14};
15
16[numthreads(1, 1, 1)]
17void main() {
18  Pair Vals = {1, 2.0};
19  Vals.First = Vals.getFirst();
20  Vals.Second = Vals.getSecond();
21}
22
23// This tests reference like `this` in HLSL
24  // CHECK:       %call = call noundef i32 @_ZN4Pair8getFirstEv(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
25  // CHECK-NEXT:  %First = getelementptr inbounds nuw %struct.Pair, ptr %Vals, i32 0, i32 0
26  // CHECK-NEXT:  store i32 %call, ptr %First, align 4
27  // CHECK-NEXT:  %call1 = call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) float @_ZN4Pair9getSecondEv(ptr noundef nonnull align 4 dereferenceable(8) %Vals)
28  // CHECK-NEXT:  %Second = getelementptr inbounds nuw %struct.Pair, ptr %Vals, i32 0, i32 1
29
30// CHECK: [[Pair:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair"
31// CHECK: [[getFirst:![0-9]+]] = distinct !DISubprogram(name: "getFirst"
32// CHECK-SAME: scope: [[Pair]]
33// CHECK: [[FirstThis:![0-9]+]] = !DILocalVariable(name: "this", arg: 1, scope: [[getFirst]], type: [[thisType:![0-9]+]]
34// CHECK: [[thisType]] = !DIDerivedType(tag: DW_TAG_reference_type, baseType: [[Pair]], size: 32)
35