1 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -emit-llvm -o - | FileCheck %s 2 3 template<typename T> 4 struct S { 5 static int n; 6 }; 7 template<typename T> int S<T>::n = 5; 8 9 int f() { 10 // Make sure that the reference here is enough to trigger the instantiation of 11 // the static data member. 12 // CHECK: @_ZN1SIiE1nE = linkonce_odr global i32 5 13 int a[S<int>::n]; 14 return sizeof a; 15 } 16 17 // rdar://problem/9506377 18 void test0(void *array, int n) { 19 // CHECK-LABEL: define void @_Z5test0Pvi( 20 // CHECK: [[ARRAY:%.*]] = alloca i8*, align 8 21 // CHECK-NEXT: [[N:%.*]] = alloca i32, align 4 22 // CHECK-NEXT: [[REF:%.*]] = alloca i16*, align 8 23 // CHECK-NEXT: [[S:%.*]] = alloca i16, align 2 24 // CHECK-NEXT: store i8* 25 // CHECK-NEXT: store i32 26 27 // Capture the bounds. 28 // CHECK-NEXT: [[T0:%.*]] = load i32, i32* [[N]], align 4 29 // CHECK-NEXT: [[DIM0:%.*]] = zext i32 [[T0]] to i64 30 // CHECK-NEXT: [[T0:%.*]] = load i32, i32* [[N]], align 4 31 // CHECK-NEXT: [[T1:%.*]] = add nsw i32 [[T0]], 1 32 // CHECK-NEXT: [[DIM1:%.*]] = zext i32 [[T1]] to i64 33 typedef short array_t[n][n+1]; 34 35 // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[ARRAY]], align 8 36 // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i16* 37 // CHECK-NEXT: store i16* [[T1]], i16** [[REF]], align 8 38 array_t &ref = *(array_t*) array; 39 40 // CHECK-NEXT: [[T0:%.*]] = load i16*, i16** [[REF]] 41 // CHECK-NEXT: [[T1:%.*]] = mul nsw i64 1, [[DIM1]] 42 // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16, i16* [[T0]], i64 [[T1]] 43 // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16, i16* [[T2]], i64 2 44 // CHECK-NEXT: store i16 3, i16* [[T3]] 45 ref[1][2] = 3; 46 47 // CHECK-NEXT: [[T0:%.*]] = load i16*, i16** [[REF]] 48 // CHECK-NEXT: [[T1:%.*]] = mul nsw i64 4, [[DIM1]] 49 // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i16, i16* [[T0]], i64 [[T1]] 50 // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i16, i16* [[T2]], i64 5 51 // CHECK-NEXT: [[T4:%.*]] = load i16, i16* [[T3]] 52 // CHECK-NEXT: store i16 [[T4]], i16* [[S]], align 2 53 short s = ref[4][5]; 54 55 // CHECK-NEXT: ret void 56 } 57