1// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
2// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
3
4int &f();
5
6// LINUX: @r = thread_local global i32* null
7// DARWIN: @r = internal thread_local global i32* null
8thread_local int &r = f();
9
10// LINUX: @_ZTH1r = alias void (), void ()* @__tls_init
11// DARWIN: @_ZTH1r = internal alias void (), void ()* @__tls_init
12
13int &g() { return r; }
14
15// CHECK: define {{.*}} @[[R_INIT:.*]]()
16// CHECK: call dereferenceable({{[0-9]+}}) i32* @_Z1fv()
17// CHECK: store i32* %{{.*}}, i32** @r, align 8
18
19// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i32* @_Z1gv()
20// LINUX: call i32* @_ZTW1r()
21// DARWIN: call cxx_fast_tlscc i32* @_ZTW1r()
22// CHECK: ret i32* %{{.*}}
23
24// LINUX: define weak_odr hidden i32* @_ZTW1r() [[ATTR0:#[0-9]+]] {
25// DARWIN: define cxx_fast_tlscc i32* @_ZTW1r() [[ATTR1:#[0-9]+]] {
26// LINUX: call void @_ZTH1r()
27// DARWIN: call cxx_fast_tlscc void @_ZTH1r()
28// CHECK: load i32*, i32** @r, align 8
29// CHECK: ret i32* %{{.*}}
30
31// LINUX-LABEL: define internal void @__tls_init()
32// DARWIN-LABEL: define internal cxx_fast_tlscc void @__tls_init()
33// CHECK: call void @[[R_INIT]]()
34
35// LINUX: attributes [[ATTR0]] = { {{.*}}"target-features"{{.*}} }
36// DARWIN: attributes [[ATTR1]] = { {{.*}}nounwind{{.*}}"target-features"{{.*}}  }
37