2011-06-25 05:55:10 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s
|
|
|
|
|
2011-12-20 10:08:33 +08:00
|
|
|
template<typename T>
|
|
|
|
struct S {
|
|
|
|
static int n;
|
|
|
|
};
|
|
|
|
template<typename T> int S<T>::n = 5;
|
|
|
|
|
|
|
|
int f() {
|
|
|
|
// Make sure that the reference here is enough to trigger the instantiation of
|
|
|
|
// the static data member.
|
2014-04-29 06:17:59 +08:00
|
|
|
// CHECK: @_ZN1SIiE1nE = linkonce_odr global i32 5
|
2011-12-20 10:08:33 +08:00
|
|
|
int a[S<int>::n];
|
|
|
|
return sizeof a;
|
|
|
|
}
|
|
|
|
|
2011-06-25 05:55:10 +08:00
|
|
|
// rdar://problem/9506377
|
|
|
|
void test0(void *array, int n) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z5test0Pvi(
|
2011-06-25 05:55:10 +08:00
|
|
|
// CHECK: [[ARRAY:%.*]] = alloca i8*, align 8
|
|
|
|
// CHECK-NEXT: [[N:%.*]] = alloca i32, align 4
|
|
|
|
// CHECK-NEXT: [[REF:%.*]] = alloca i16*, align 8
|
|
|
|
// CHECK-NEXT: [[S:%.*]] = alloca i16, align 2
|
|
|
|
// CHECK-NEXT: store i8*
|
|
|
|
// CHECK-NEXT: store i32
|
|
|
|
|
|
|
|
// Capture the bounds.
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i32, i32* [[N]], align 4
|
2011-06-25 05:55:10 +08:00
|
|
|
// CHECK-NEXT: [[DIM0:%.*]] = zext i32 [[T0]] to i64
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i32, i32* [[N]], align 4
|
2011-06-25 05:55:10 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = add nsw i32 [[T0]], 1
|
|
|
|
// CHECK-NEXT: [[DIM1:%.*]] = zext i32 [[T1]] to i64
|
|
|
|
typedef short array_t[n][n+1];
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[ARRAY]], align 8
|
2011-06-25 05:55:10 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i16*
|
|
|
|
// CHECK-NEXT: store i16* [[T1]], i16** [[REF]], align 8
|
|
|
|
array_t &ref = *(array_t*) array;
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i16*, i16** [[REF]]
|
2011-06-25 09:32:37 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = mul nsw i64 1, [[DIM1]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16, i16* [[T0]], i64 [[T1]]
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16, i16* [[T2]], i64 2
|
2011-06-25 05:55:10 +08:00
|
|
|
// CHECK-NEXT: store i16 3, i16* [[T3]]
|
|
|
|
ref[1][2] = 3;
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load i16*, i16** [[REF]]
|
2011-06-25 09:32:37 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = mul nsw i64 4, [[DIM1]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16, i16* [[T0]], i64 [[T1]]
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16, i16* [[T2]], i64 5
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T4:%.*]] = load i16, i16* [[T3]]
|
2011-06-25 05:55:10 +08:00
|
|
|
// CHECK-NEXT: store i16 [[T4]], i16* [[S]], align 2
|
|
|
|
short s = ref[4][5];
|
|
|
|
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|