| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s |
| 5 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s |
| 7 |
|
| 8 |
struct Point { |
| 9 |
int x, y; |
| 10 |
}; |
| 11 |
|
| 12 |
struct Line { |
| 13 |
struct Point start; |
| 14 |
struct Point end; |
| 15 |
}; |
| 16 |
|
| 17 |
// AggExprEmitter::VisitMemberExpr |
| 18 |
void test_member_in_array(void) { |
| 19 |
struct Line line = {{1, 2}, {3, 4}}; |
| 20 |
struct Point arr[1] = {line.start}; |
| 21 |
} |
| 22 |
|
| 23 |
// CIR-LABEL: cir.func{{.*}} @test_member_in_array |
| 24 |
// CIR: %[[LINE:.*]] = cir.alloca !rec_Line{{.*}}, ["line", init] |
| 25 |
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 1>{{.*}}, ["arr", init] |
| 26 |
// CIR: %[[MEMBER:.*]] = cir.get_member %[[LINE]][0] {name = "start"} |
| 27 |
// CIR: cir.copy |
| 28 |
|
| 29 |
// LLVM-LABEL: define{{.*}} @test_member_in_array |
| 30 |
// LLVM: %[[LINE:.*]] = alloca %struct.Line |
| 31 |
// LLVM: %[[ARR:.*]] = alloca [1 x %struct.Point] |
| 32 |
// LLVM: %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LINE]]{{.*}}i32 0, i32 0 |
| 33 |
// LLVM: call void @llvm.memcpy |
| 34 |
|
| 35 |
// OGCG-LABEL: define{{.*}} @test_member_in_array |
| 36 |
// OGCG: %[[LINE:.*]] = alloca %struct.Line |
| 37 |
// OGCG: %[[ARR:.*]] = alloca [1 x %struct.Point] |
| 38 |
// OGCG: %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LINE]]{{.*}}i32 0, i32 0 |
| 39 |
// OGCG: call void @llvm.memcpy |
| 40 |
|
| 41 |
// AggExprEmitter::VisitMemberExpr |
| 42 |
void test_member_arrow_in_array(void) { |
| 43 |
struct Line *line_ptr; |
| 44 |
struct Point arr[1] = {line_ptr->start}; |
| 45 |
} |
| 46 |
|
| 47 |
// CIR-LABEL: cir.func{{.*}} @test_member_arrow_in_array |
| 48 |
// CIR: %[[PTR:.*]] = cir.alloca !cir.ptr<!rec_Line>{{.*}}, ["line_ptr"] |
| 49 |
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 1>{{.*}}, ["arr", init] |
| 50 |
// CIR: %[[LOADED:.*]] = cir.load{{.*}}%[[PTR]] |
| 51 |
// CIR: %[[MEMBER:.*]] = cir.get_member %[[LOADED]][0] {name = "start"} |
| 52 |
// CIR: cir.copy |
| 53 |
|
| 54 |
// LLVM-LABEL: define{{.*}} @test_member_arrow_in_array |
| 55 |
// LLVM: %[[PTR:.*]] = alloca ptr |
| 56 |
// LLVM: %[[ARR:.*]] = alloca [1 x %struct.Point] |
| 57 |
// LLVM: %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]] |
| 58 |
// LLVM: %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LOADED]]{{.*}}i32 0, i32 0 |
| 59 |
// LLVM: call void @llvm.memcpy |
| 60 |
|
| 61 |
// OGCG-LABEL: define{{.*}} @test_member_arrow_in_array |
| 62 |
// OGCG: %[[PTR:.*]] = alloca ptr |
| 63 |
// OGCG: %[[ARR:.*]] = alloca [1 x %struct.Point] |
| 64 |
// OGCG: %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]] |
| 65 |
// OGCG: %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LOADED]]{{.*}}i32 0, i32 0 |
| 66 |
// OGCG: call void @llvm.memcpy |
| 67 |
|
| 68 |
// AggExprEmitter::VisitUnaryDeref |
| 69 |
void test_deref_in_array(void) { |
| 70 |
struct Point *ptr; |
| 71 |
struct Point arr[1] = {*ptr}; |
| 72 |
} |
| 73 |
|
| 74 |
// CIR-LABEL: cir.func{{.*}} @test_deref_in_array |
| 75 |
// CIR: %[[PTR:.*]] = cir.alloca !cir.ptr<!rec_Point>{{.*}}, ["ptr"] |
| 76 |
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 1>{{.*}}, ["arr", init] |
| 77 |
// CIR: %[[LOADED:.*]] = cir.load{{.*}}%[[PTR]] |
| 78 |
// CIR: cir.copy |
| 79 |
|
| 80 |
// LLVM-LABEL: define{{.*}} @test_deref_in_array |
| 81 |
// LLVM: %[[PTR:.*]] = alloca ptr |
| 82 |
// LLVM: %[[ARR:.*]] = alloca [1 x %struct.Point] |
| 83 |
// LLVM: %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]] |
| 84 |
// LLVM: call void @llvm.memcpy |
| 85 |
|
| 86 |
// OGCG-LABEL: define{{.*}} @test_deref_in_array |
| 87 |
// OGCG: %[[PTR:.*]] = alloca ptr |
| 88 |
// OGCG: %[[ARR:.*]] = alloca [1 x %struct.Point] |
| 89 |
// OGCG: %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]] |
| 90 |
// OGCG: call void @llvm.memcpy |
| 91 |
|
| 92 |
// AggExprEmitter::VisitStringLiteral |
| 93 |
void test_string_array_in_array(void) { |
| 94 |
char matrix[2][6] = {"hello", "world"}; |
| 95 |
} |
| 96 |
|
| 97 |
// CIR-LABEL: cir.func{{.*}} @test_string_array_in_array |
| 98 |
// CIR: %[[MATRIX:.*]] = cir.alloca !cir.array<!cir.array<!s8i x 6> x 2>, {{.*}}, ["matrix", init] |
| 99 |
// CIR: %[[CONST:.*]] = cir.const #cir.const_array<[#cir.const_array<[#cir.int<104> : !s8i, #cir.int<101> : !s8i, #cir.int<108> : !s8i, #cir.int<108> : !s8i, #cir.int<111> : !s8i, #cir.int<0> : !s8i]> : !cir.array<!s8i x 6>, #cir.const_array<[#cir.int<119> : !s8i, #cir.int<111> : !s8i, #cir.int<114> : !s8i, #cir.int<108> : !s8i, #cir.int<100> : !s8i, #cir.int<0> : !s8i]> : !cir.array<!s8i x 6>]> |
| 100 |
// CIR: cir.store{{.*}} %[[CONST]], %[[MATRIX]] |
| 101 |
|
| 102 |
// LLVM-LABEL: define{{.*}} @test_string_array_in_array |
| 103 |
// LLVM: %[[MATRIX:.*]] = alloca [2 x [6 x i8]] |
| 104 |
// LLVM: store [2 x [6 x i8]] {{\[}}[6 x i8] c"hello\00", [6 x i8] c"world\00"], ptr %[[MATRIX]] |
| 105 |
|
| 106 |
// OGCG-LABEL: define{{.*}} @test_string_array_in_array |
| 107 |
// OGCG: alloca [2 x [6 x i8]] |
| 108 |
// OGCG: call void @llvm.memcpy{{.*}}@__const.test_string_array_in_array |