brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 509f021 Raw
109 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s7 8struct Point {9  int x, y;10};11 12struct Line {13  struct Point start;14  struct Point end;15};16 17// AggExprEmitter::VisitMemberExpr18void 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_array24// 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.copy28 29// LLVM-LABEL: define{{.*}} @test_member_in_array30// LLVM:   %[[LINE:.*]] = alloca %struct.Line31// LLVM:   %[[ARR:.*]] = alloca [1 x %struct.Point]32// LLVM:   %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LINE]]{{.*}}i32 0, i32 033// LLVM:   call void @llvm.memcpy34 35// OGCG-LABEL: define{{.*}} @test_member_in_array36// OGCG:   %[[LINE:.*]] = alloca %struct.Line37// OGCG:   %[[ARR:.*]] = alloca [1 x %struct.Point]38// OGCG:   %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LINE]]{{.*}}i32 0, i32 039// OGCG:   call void @llvm.memcpy40 41// AggExprEmitter::VisitMemberExpr42void 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_array48// 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.copy53 54// LLVM-LABEL: define{{.*}} @test_member_arrow_in_array55// LLVM:   %[[PTR:.*]] = alloca ptr56// LLVM:   %[[ARR:.*]] = alloca [1 x %struct.Point]57// LLVM:   %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]]58// LLVM:   %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LOADED]]{{.*}}i32 0, i32 059// LLVM:   call void @llvm.memcpy60 61// OGCG-LABEL: define{{.*}} @test_member_arrow_in_array62// OGCG:   %[[PTR:.*]] = alloca ptr63// OGCG:   %[[ARR:.*]] = alloca [1 x %struct.Point]64// OGCG:   %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]]65// OGCG:   %[[MEMBER:.*]] = getelementptr{{.*}}%struct.Line{{.*}}%[[LOADED]]{{.*}}i32 0, i32 066// OGCG:   call void @llvm.memcpy67 68// AggExprEmitter::VisitUnaryDeref69void 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_array75// 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.copy79 80// LLVM-LABEL: define{{.*}} @test_deref_in_array81// LLVM:   %[[PTR:.*]] = alloca ptr82// LLVM:   %[[ARR:.*]] = alloca [1 x %struct.Point]83// LLVM:   %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]]84// LLVM:   call void @llvm.memcpy85 86// OGCG-LABEL: define{{.*}} @test_deref_in_array87// OGCG:   %[[PTR:.*]] = alloca ptr88// OGCG:   %[[ARR:.*]] = alloca [1 x %struct.Point]89// OGCG:   %[[LOADED:.*]] = load ptr{{.*}}%[[PTR]]90// OGCG:   call void @llvm.memcpy91 92// AggExprEmitter::VisitStringLiteral93void test_string_array_in_array(void) {94    char matrix[2][6] = {"hello", "world"};95}96  97// CIR-LABEL: cir.func{{.*}} @test_string_array_in_array98// 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_array103// 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_array107// OGCG:   alloca [2 x [6 x i8]]108// OGCG:   call void @llvm.memcpy{{.*}}@__const.test_string_array_in_array109