2013-07-05 00:16:58 +08:00
|
|
|
// RUN: not %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
|
2009-04-11 09:08:03 +08:00
|
|
|
|
2009-11-22 07:56:04 +08:00
|
|
|
// CHECK: @a = global i32 10
|
2009-04-11 09:08:03 +08:00
|
|
|
int a = 10;
|
2010-02-09 05:46:50 +08:00
|
|
|
// CHECK: @ar = constant i32* @a
|
2009-04-11 09:08:03 +08:00
|
|
|
int &ar = a;
|
|
|
|
|
|
|
|
void f();
|
2010-02-09 05:46:50 +08:00
|
|
|
// CHECK: @fr = constant void ()* @_Z1fv
|
2009-04-11 09:08:03 +08:00
|
|
|
void (&fr)() = f;
|
|
|
|
|
|
|
|
struct S { int& a; };
|
2011-06-20 12:01:35 +08:00
|
|
|
// CHECK: @s = global %struct.S { i32* @a }
|
2009-04-11 09:08:03 +08:00
|
|
|
S s = { a };
|
|
|
|
|
2009-11-22 07:56:04 +08:00
|
|
|
// PR5581
|
|
|
|
namespace PR5581 {
|
|
|
|
class C {
|
|
|
|
public:
|
|
|
|
enum { e0, e1 };
|
|
|
|
unsigned f;
|
|
|
|
};
|
|
|
|
|
2011-06-20 12:01:35 +08:00
|
|
|
// CHECK: @_ZN6PR55812g0E = global %"class.PR5581::C" { i32 1 }
|
2009-11-22 07:56:04 +08:00
|
|
|
C g0 = { C::e1 };
|
|
|
|
}
|
2010-10-09 09:34:31 +08:00
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
struct A {
|
|
|
|
static const double d = 1.0;
|
|
|
|
static const float f = d / 2;
|
2011-11-13 06:28:03 +08:00
|
|
|
static int g();
|
|
|
|
} a;
|
2010-10-09 09:34:31 +08:00
|
|
|
|
2010-10-09 10:28:39 +08:00
|
|
|
// CHECK: @_ZN5test22t0E = global double {{1\.0+e\+0+}}, align 8
|
|
|
|
// CHECK: @_ZN5test22t1E = global [2 x double] [double {{1\.0+e\+0+}}, double {{5\.0+e-0*}}1], align 16
|
2011-11-13 06:28:03 +08:00
|
|
|
// CHECK: @_ZN5test22t2E = global double* @_ZN5test21A1d
|
|
|
|
// CHECK: @_ZN5test22t3E = global {{.*}} @_ZN5test21A1g
|
2010-10-09 09:34:31 +08:00
|
|
|
double t0 = A::d;
|
|
|
|
double t1[] = { A::d, A::f };
|
2011-11-13 06:28:03 +08:00
|
|
|
const double *t2 = &a.d;
|
|
|
|
int (*t3)() = &a.g;
|
2010-10-09 09:34:31 +08:00
|
|
|
}
|
2011-10-25 06:25:55 +08:00
|
|
|
|
|
|
|
// We don't expect to fold this in the frontend, but make sure it doesn't crash.
|
|
|
|
// CHECK: @PR9558 = global float 0.000000e+0
|
|
|
|
float PR9558 = reinterpret_cast<const float&>("asd");
|
2011-12-02 08:30:33 +08:00
|
|
|
|
|
|
|
// An initialized const automatic variable cannot be promoted to a constant
|
|
|
|
// global if it has a mutable member.
|
|
|
|
struct MutableMember {
|
|
|
|
mutable int n;
|
|
|
|
};
|
|
|
|
int writeToMutable() {
|
|
|
|
// CHECK-NOT: {{.*}}MM{{.*}} = {{.*}}constant
|
|
|
|
const MutableMember MM = { 0 };
|
|
|
|
return ++MM.n;
|
|
|
|
}
|
2012-01-05 07:13:47 +08:00
|
|
|
|
|
|
|
// Make sure we don't try to fold this in the frontend; the backend can't
|
|
|
|
// handle it.
|
|
|
|
// CHECK: @PR11705 = global i128 0
|
|
|
|
__int128_t PR11705 = (__int128_t)&PR11705;
|
|
|
|
|
|
|
|
// Make sure we don't try to fold this either.
|
|
|
|
// CHECK: @_ZZ23UnfoldableAddrLabelDiffvE1x = internal global i128 0
|
|
|
|
void UnfoldableAddrLabelDiff() { static __int128_t x = (long)&&a-(long)&&b; a:b:return;}
|
|
|
|
|
|
|
|
// But make sure we do fold this.
|
2012-01-05 07:41:09 +08:00
|
|
|
// CHECK: @_ZZ21FoldableAddrLabelDiffvE1x = internal global i64 sub (i64 ptrtoint (i8* blockaddress(@_Z21FoldableAddrLabelDiffv
|
2012-01-05 07:13:47 +08:00
|
|
|
void FoldableAddrLabelDiff() { static long x = (long)&&a-(long)&&b; a:b:return;}
|
2012-01-12 14:08:57 +08:00
|
|
|
|
|
|
|
// CHECK: @i = constant i32* bitcast (float* @PR9558 to i32*)
|
|
|
|
int &i = reinterpret_cast<int&>(PR9558);
|
|
|
|
|
|
|
|
int arr[2];
|
|
|
|
// CHECK: @pastEnd = constant i32* bitcast (i8* getelementptr (i8* bitcast ([2 x i32]* @arr to i8*), i64 8) to i32*)
|
|
|
|
int &pastEnd = arr[2];
|