| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm -disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s |
| 2 |
|
| 3 |
struct Pair { |
| 4 |
int First; |
| 5 |
int Second; |
| 6 |
|
| 7 |
int getFirst() { |
| 8 |
Pair Another = {5, 10}; |
| 9 |
this = Another; |
| 10 |
return this.First; |
| 11 |
} |
| 12 |
|
| 13 |
int getSecond() { |
| 14 |
this = Pair(); |
| 15 |
return Second; |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
[numthreads(1, 1, 1)] |
| 20 |
void main() { |
| 21 |
Pair Vals = {1, 2.0}; |
| 22 |
Vals.First = Vals.getFirst(); |
| 23 |
Vals.Second = Vals.getSecond(); |
| 24 |
} |
| 25 |
|
| 26 |
// This tests reference like implicit this in HLSL |
| 27 |
// CHECK: define linkonce_odr noundef i32 @"?getFirst@Pair@@QAAHXZ"(ptr noundef nonnull align 4 dereferenceable(8) %this) #3 align 2 { |
| 28 |
// CHECK-NEXT:entry: |
| 29 |
// CHECK-NEXT:%this.addr = alloca ptr, align 4 |
| 30 |
// CHECK-NEXT:%Another = alloca %struct.Pair, align 4 |
| 31 |
// CHECK-NEXT:store ptr %this, ptr %this.addr, align 4 |
| 32 |
// CHECK-NEXT:%this1 = load ptr, ptr %this.addr, align 4 |
| 33 |
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %Another, ptr align 4 @"__const.?getFirst@Pair@@QAAHXZ.Another", i32 8, i1 false) |
| 34 |
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %this1, ptr align 4 %Another, i32 8, i1 false) |
| 35 |
// CHECK-NEXT:%First = getelementptr inbounds %struct.Pair, ptr %this1, i32 0, i32 0 |
| 36 |
|
| 37 |
// CHECK: define linkonce_odr noundef i32 @"?getSecond@Pair@@QAAHXZ"(ptr noundef nonnull align 4 dereferenceable(8) %this) #3 align 2 { |
| 38 |
// CHECK-NEXT:entry: |
| 39 |
// CHECK-NEXT:%this.addr = alloca ptr, align 4 |
| 40 |
// CHECK-NEXT:%ref.tmp = alloca %struct.Pair, align 4 |
| 41 |
// CHECK-NEXT:store ptr %this, ptr %this.addr, align 4 |
| 42 |
// CHECK-NEXT:%this1 = load ptr, ptr %this.addr, align 4 |
| 43 |
// CHECK-NEXT:call void @llvm.memset.p0.i32(ptr align 4 %ref.tmp, i8 0, i32 8, i1 false) |
| 44 |
// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i32(ptr align 4 %this1, ptr align 4 %ref.tmp, i32 8, i1 false) |
| 45 |
// CHECK-NEXT:%Second = getelementptr inbounds %struct.Pair, ptr %this1, i32 0, i32 1 |