1// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
2
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 things
22// 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, 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