brintos

brintos / llvm-project-archived public Read only

0
0
Text · 962 B · 781f5e4 Raw
32 lines · cpp
1// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s2 3template <typename T>4struct HasStaticInit {5static const int index;6};7extern "C"8int the_count = 0;9template <typename T>10const int HasStaticInit<T>::index = the_count++;11 12template <typename T> int func_tmpl1() { return HasStaticInit<T>::index; }13template <typename T> int func_tmpl2() { return HasStaticInit<T>::index; }14template <typename T> int func_tmpl3() { return HasStaticInit<T>::index; }15void useit() {16  func_tmpl1<int>();17  func_tmpl2<int>();18  func_tmpl3<int>();19}20 21// Throw in a final explicit instantiation to see that it doesn't screw things22// up.23template struct HasStaticInit<int>;24 25// There should only be one entry, not 3.26// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }]27 28// There should only be one update to @the_count.29// CHECK-NOT: store i32 %{{.*}}, ptr @the_count30// CHECK: store i32 %{{.*}}, ptr @the_count31// CHECK-NOT: store i32 %{{.*}}, ptr @the_count32