| 1 |
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s |
| 2 |
|
| 3 |
void escape(const void *); |
| 4 |
|
| 5 |
// CHECK-DAG: internal global i8 99 |
| 6 |
|
| 7 |
void T1(void) { |
| 8 |
const char *x[1] = {({static char _x = 99; &_x; })}; |
| 9 |
escape(x); |
| 10 |
} |
| 11 |
|
| 12 |
struct sized_array { |
| 13 |
int count; |
| 14 |
int entries[]; |
| 15 |
}; |
| 16 |
|
| 17 |
#define N_ARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int)) |
| 18 |
|
| 19 |
#define ARRAY_PTR(...) ({ \ |
| 20 |
static const struct sized_array _a = {N_ARGS(__VA_ARGS__), {__VA_ARGS__}}; \ |
| 21 |
&_a; \ |
| 22 |
}) |
| 23 |
|
| 24 |
struct outer { |
| 25 |
const struct sized_array *a; |
| 26 |
}; |
| 27 |
|
| 28 |
void T2(void) { |
| 29 |
// CHECK-DAG: internal constant { i32, [2 x i32] } { i32 2, [2 x i32] [i32 50, i32 60] } |
| 30 |
const struct sized_array *A = ARRAY_PTR(50, 60); |
| 31 |
|
| 32 |
// CHECK-DAG: internal constant { i32, [3 x i32] } { i32 3, [3 x i32] [i32 10, i32 20, i32 30] } |
| 33 |
struct outer X = {ARRAY_PTR(10, 20, 30)}; |
| 34 |
|
| 35 |
escape(A); |
| 36 |
escape(&X); |
| 37 |
} |