Debian Codegraph @

clang/test/CodeGenHLSL/GlobalDestructors.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,CHECK
2 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=LIB,CHECK
3
4 // Make sure global variable for dtors exist for lib profile.
5 // LIB:@llvm.global_dtors
6 // Make sure global variable for dtors removed for compute profile.
7 // CS-NOT:llvm.global_dtors
8
9 struct Tail {
10 Tail() {
11 add(1);
12 }
13
14 ~Tail() {
15 add(-1);
16 }
17
18 void add(int V) {
19 static int Count = 0;
20 Count += V;
21 }
22 };
23
24 struct Pupper {
25 static int Count;
26
27 Pupper() {
28 Count += 1; // :)
29 }
30
31 ~Pupper() {
32 Count -= 1; // :(
33 }
34 } GlobalPup;
35
36 void Wag() {
37 static Tail T;
38 T.add(0);
39 }
40
41 int Pupper::Count = 0;
42
43 [numthreads(1,1,1)]
44 [shader("compute")]
45 void main(unsigned GI : SV_GroupIndex) {
46 Wag();
47 }
48
49 // Make sure global variable for ctors/dtors removed.
50 // CHECK-NOT:@llvm.global_ctors
51 // CHECK-NOT:@llvm.global_dtors
52 //CHECK: define void @main()
53 //CHECK-NEXT: entry:
54 //CHECK-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
55 //CHECK-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
56 //CHECK-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
57 //CHECK-NEXT: call void @_GLOBAL__D_a()
58 //CHECK-NEXT: ret void
59
60 // This is really just a sanity check I needed for myself to verify that
61 // function scope static variables also get destroyed properly.
62
63 //CHECK: define internal void @_GLOBAL__D_a()
64 //CHECK-NEXT: entry:
65 //CHECK-NEXT: call void @"??1Tail@@QAA@XZ"(ptr @"?T@?1??Wag@@YAXXZ@4UTail@@A")
66 //CHECK-NEXT: call void @"??1Pupper@@QAA@XZ"(ptr @"?GlobalPup@@3UPupper@@A")
67 //CHECK-NEXT: ret void