1 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s 2 3 // CHECK: @a = global i32 10 4 int a = 10; 5 // CHECK: @ar = constant i32* @a 6 int &ar = a; 7 8 void f(); 9 // CHECK: @fr = constant void ()* @_Z1fv 10 void (&fr)() = f; 11 12 struct S { int& a; }; 13 // CHECK: @s = global %struct.S { i32* @a } 14 S s = { a }; 15 16 // PR5581 17 namespace PR5581 { 18 class C { 19 public: 20 enum { e0, e1 }; 21 unsigned f; 22 }; 23 24 // CHECK: @_ZN6PR55812g0E = global %"class.PR5581::C" { i32 1 } 25 C g0 = { C::e1 }; 26 } 27 28 namespace test2 { 29 struct A { 30 static const double d = 1.0; 31 static const float f = d / 2; 32 static int g(); 33 } a; 34 35 // CHECK: @_ZN5test22t0E = global double {{1\.0+e\+0+}}, align 8 36 // CHECK: @_ZN5test22t1E = global [2 x double] [double {{1\.0+e\+0+}}, double {{5\.0+e-0*}}1], align 16 37 // CHECK: @_ZN5test22t2E = global double* @_ZN5test21A1d 38 // CHECK: @_ZN5test22t3E = global {{.*}} @_ZN5test21A1g 39 double t0 = A::d; 40 double t1[] = { A::d, A::f }; 41 const double *t2 = &a.d; 42 int (*t3)() = &a.g; 43 } 44 45 // We don't expect to fold this in the frontend, but make sure it doesn't crash. 46 // CHECK: @PR9558 = global float 0.000000e+0 47 float PR9558 = reinterpret_cast<const float&>("asd"); 48 49 // An initialized const automatic variable cannot be promoted to a constant 50 // global if it has a mutable member. 51 struct MutableMember { 52 mutable int n; 53 }; 54 int writeToMutable() { 55 // CHECK-NOT: {{.*}}MM{{.*}} = {{.*}}constant 56 const MutableMember MM = { 0 }; 57 return ++MM.n; 58 } 59