xref: /aosp_15_r20/external/clang/test/CodeGenCXX/static-data-member-single-emission.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
2*67e74705SXin Li 
3*67e74705SXin Li template <typename T>
4*67e74705SXin Li struct HasStaticInit {
5*67e74705SXin Li static const int index;
6*67e74705SXin Li };
7*67e74705SXin Li extern "C"
8*67e74705SXin Li int the_count = 0;
9*67e74705SXin Li template <typename T>
10*67e74705SXin Li const int HasStaticInit<T>::index = the_count++;
11*67e74705SXin Li 
func_tmpl1()12*67e74705SXin Li template <typename T> int func_tmpl1() { return HasStaticInit<T>::index; }
func_tmpl2()13*67e74705SXin Li template <typename T> int func_tmpl2() { return HasStaticInit<T>::index; }
func_tmpl3()14*67e74705SXin Li template <typename T> int func_tmpl3() { return HasStaticInit<T>::index; }
useit()15*67e74705SXin Li void useit() {
16*67e74705SXin Li   func_tmpl1<int>();
17*67e74705SXin Li   func_tmpl2<int>();
18*67e74705SXin Li   func_tmpl3<int>();
19*67e74705SXin Li }
20*67e74705SXin Li 
21*67e74705SXin Li // Throw in a final explicit instantiation to see that it doesn't screw things
22*67e74705SXin Li // up.
23*67e74705SXin Li template struct HasStaticInit<int>;
24*67e74705SXin Li 
25*67e74705SXin Li // There should only be one entry, not 3.
26*67e74705SXin Li // CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }]
27*67e74705SXin Li 
28*67e74705SXin Li // There should only be one update to @the_count.
29*67e74705SXin Li // CHECK-NOT: store i32 %{{.*}}, i32* @the_count
30*67e74705SXin Li // CHECK: store i32 %{{.*}}, i32* @the_count
31*67e74705SXin Li // CHECK-NOT: store i32 %{{.*}}, i32* @the_count
32