Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
      2 
      3 template <typename T>
      4 struct HasStaticInit {
      5 static const int index;
      6 };
      7 extern "C"
      8 int the_count = 0;
      9 template <typename T>
     10 const int HasStaticInit<T>::index = the_count++;
     11 
     12 template <typename T> int func_tmpl1() { return HasStaticInit<T>::index; }
     13 template <typename T> int func_tmpl2() { return HasStaticInit<T>::index; }
     14 template <typename T> int func_tmpl3() { return HasStaticInit<T>::index; }
     15 void 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 things
     22 // up.
     23 template struct HasStaticInit<int>;
     24 
     25 // There should only be one entry, not 3.
     26 // CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }]
     27 
     28 // There should only be one update to @the_count.
     29 // CHECK-NOT: store i32 %{{.*}}, i32* @the_count
     30 // CHECK: store i32 %{{.*}}, i32* @the_count
     31 // CHECK-NOT: store i32 %{{.*}}, i32* @the_count
     32