brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.2 KiB · 4520063 Raw
207 lines · c
1// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir 2> %t-before-lp.cir2// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR3// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM5// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG7 8void binary_assign(void) {9    bool b;10    char c;11    float f;12    int i;13 14    b = true;15    c = 65;16    f = 3.14f;17    i = 42;18}19 20// CIR-LABEL: cir.func{{.*}} @binary_assign()21// CIR:         %[[B:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b"]22// CIR:         %[[C:.*]] = cir.alloca !s8i, !cir.ptr<!s8i>, ["c"]23// CIR:         %[[F:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["f"]24// CIR:         %[[I:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i"]25// CIR:         %[[TRUE:.*]] = cir.const #true26// CIR:         cir.store{{.*}} %[[TRUE]], %[[B]] : !cir.bool, !cir.ptr<!cir.bool>27// CIR:         %[[CHAR_INI_INIT:.*]] = cir.const #cir.int<65> : !s32i28// CIR:         %[[CHAR_VAL:.*]] = cir.cast integral %[[CHAR_INI_INIT]] : !s32i -> !s8i29// CIR:         cir.store{{.*}} %[[CHAR_VAL]], %[[C]] : !s8i, !cir.ptr<!s8i>30// CIR:         %[[FLOAT_VAL:.*]] = cir.const #cir.fp<3.140000e+00> : !cir.float31// CIR:         cir.store{{.*}} %[[FLOAT_VAL]], %[[F]] : !cir.float, !cir.ptr<!cir.float>32// CIR:         %[[INT_VAL:.*]] = cir.const #cir.int<42> : !s32i33// CIR:         cir.store{{.*}} %[[INT_VAL]], %[[I]] : !s32i, !cir.ptr<!s32i>34// CIR:         cir.return35 36// LLVM-LABEL: define {{.*}}void @binary_assign(){{.*}} {37// LLVM:         %[[B_PTR:.*]] = alloca i838// LLVM:         %[[C_PTR:.*]] = alloca i839// LLVM:         %[[F_PTR:.*]] = alloca float40// LLVM:         %[[I_PTR:.*]] = alloca i3241// LLVM:         store i8 1, ptr %[[B_PTR]]42// LLVM:         store i8 65, ptr %[[C_PTR]]43// LLVM:         store float 0x40091EB860000000, ptr %[[F_PTR]]44// LLVM:         store i32 42, ptr %[[I_PTR]]45// LLVM:         ret void46 47// OGCG-LABEL: define {{.*}}void @binary_assign()48// OGCG:         %[[B_PTR:.*]] = alloca i849// OGCG:         %[[C_PTR:.*]] = alloca i850// OGCG:         %[[F_PTR:.*]] = alloca float51// OGCG:         %[[I_PTR:.*]] = alloca i3252// OGCG:         store i8 1, ptr %[[B_PTR]]53// OGCG:         store i8 65, ptr %[[C_PTR]]54// OGCG:         store float 0x40091EB860000000, ptr %[[F_PTR]]55// OGCG:         store i32 42, ptr %[[I_PTR]]56// OGCG:         ret void57 58struct S {59  int a;60  float b;61};62 63struct SV {64  int a;65  volatile float b;66};67 68struct S gs;69struct SV gsv;70 71void binary_assign_struct() {72  // Test normal struct assignment73  struct S ls;74  ls = gs;75 76  // Test assignment of a struct with a volatile member77  struct SV lsv;78  lsv = gsv;79}80 81// CIR: cir.func{{.*}} @binary_assign_struct()82// CIR:   %[[LS:.*]] = cir.alloca ![[REC_S:.*]], !cir.ptr<![[REC_S]]>, ["ls"]83// CIR:   %[[LSV:.*]] = cir.alloca ![[REC_SV:.*]], !cir.ptr<![[REC_SV]]>, ["lsv"]84// CIR:   %[[GS_PTR:.*]] = cir.get_global @gs : !cir.ptr<![[REC_S]]>85// CIR:   cir.copy %[[GS_PTR]] to %[[LS]] : !cir.ptr<![[REC_S]]>86// CIR:   %[[GSV_PTR:.*]] = cir.get_global @gsv : !cir.ptr<![[REC_SV]]>87// CIR:   cir.copy %[[GSV_PTR]] to %[[LSV]] volatile : !cir.ptr<![[REC_SV]]>88// CIR:   cir.return89 90// LLVM: define {{.*}}void @binary_assign_struct()91// LLVM:   %[[LS_PTR:.*]] = alloca %struct.S92// LLVM:   %[[LSV_PTR:.*]] = alloca %struct.SV93// LLVM:   call void @llvm.memcpy.p0.p0.i32(ptr %[[LS_PTR]], ptr @gs, i32 8, i1 false)94// LLVM:   call void @llvm.memcpy.p0.p0.i32(ptr %[[LSV_PTR]], ptr @gsv, i32 8, i1 true)95// LLVM:   ret void96 97// OGCG: define {{.*}}void @binary_assign_struct()98// OGCG:   %[[LS_PTR:.*]] = alloca %struct.S99// OGCG:   %[[LSV_PTR:.*]] = alloca %struct.SV100// OGCG:   call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[LS_PTR]], ptr align 4 @gs, i64 8, i1 false)101// OGCG:   call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[LSV_PTR]], ptr align 4 @gsv, i64 8, i1 true)102// OGCG:   ret void103 104int ignore_result_assign() {105  int arr[10];106  int i, j;107  j = i = 123, 0;108  j = arr[i = 5];109  int *p, *q = 0;110  if(p = q)111    return 1;112  return 0;113}114 115// CIR-LABEL: cir.func{{.*}} @ignore_result_assign() -> !s32i116// CIR:         %[[RETVAL:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]117// CIR:         %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 10>, !cir.ptr<!cir.array<!s32i x 10>>, ["arr"]118// CIR:         %[[I:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i"]119// CIR:         %[[J:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["j"]120// CIR:         %[[P:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["p"]121// CIR:         %[[Q:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["q", init]122// CIR:         %[[VAL_123:.*]] = cir.const #cir.int<123> : !s32i123// CIR:         cir.store{{.*}} %[[VAL_123]], %[[I]] : !s32i, !cir.ptr<!s32i>124// CIR:         cir.store{{.*}} %[[VAL_123]], %[[J]] : !s32i, !cir.ptr<!s32i>125// CIR:         %[[VAL_0:.*]] = cir.const #cir.int<0> : !s32i126// CIR:         %[[VAL_5:.*]] = cir.const #cir.int<5> : !s32i127// CIR:         cir.store{{.*}} %[[VAL_5]], %[[I]] : !s32i, !cir.ptr<!s32i>128// CIR:         %[[ARR_DECAY:.*]] = cir.cast array_to_ptrdecay %[[ARR]] : !cir.ptr<!cir.array<!s32i x 10>> -> !cir.ptr<!s32i>129// CIR:         %[[ARR_ELEM:.*]] = cir.ptr_stride %[[ARR_DECAY]], %[[VAL_5]] : (!cir.ptr<!s32i>, !s32i) -> !cir.ptr<!s32i>130// CIR:         %[[ARR_LOAD:.*]] = cir.load{{.*}} %[[ARR_ELEM]] : !cir.ptr<!s32i>, !s32i131// CIR:         cir.store{{.*}} %[[ARR_LOAD]], %[[J]] : !s32i, !cir.ptr<!s32i>132// CIR:         %[[NULL:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i>133// CIR:         cir.store{{.*}} %[[NULL]], %[[Q]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>134// CIR:         cir.scope {135// CIR:           %[[Q_VAL:.*]] = cir.load{{.*}} %[[Q]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>136// CIR:           cir.store{{.*}} %[[Q_VAL]], %[[P]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>137// CIR:           %[[COND:.*]] = cir.cast ptr_to_bool %[[Q_VAL]] : !cir.ptr<!s32i> -> !cir.bool138// CIR:           cir.if %[[COND]] {139// CIR:             %[[ONE:.*]] = cir.const #cir.int<1> : !s32i140// CIR:             cir.store %[[ONE]], %[[RETVAL]] : !s32i, !cir.ptr<!s32i>141// CIR:             %{{.*}} = cir.load %[[RETVAL]] : !cir.ptr<!s32i>, !s32i142// CIR:             cir.return143// CIR:           }144// CIR:         }145// CIR:         %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i146// CIR:         cir.store %[[ZERO]], %[[RETVAL]] : !s32i, !cir.ptr<!s32i>147// CIR:         %{{.*}} = cir.load %[[RETVAL]] : !cir.ptr<!s32i>, !s32i148// CIR:         cir.return149 150// LLVM-LABEL: define {{.*}}i32 @ignore_result_assign()151// LLVM:         %[[RETVAL_PTR:.*]] = alloca i32152// LLVM:         %[[ARR_PTR:.*]] = alloca [10 x i32]153// LLVM:         %[[I_PTR:.*]] = alloca i32154// LLVM:         %[[J_PTR:.*]] = alloca i32155// LLVM:         %[[P_PTR:.*]] = alloca ptr156// LLVM:         %[[Q_PTR:.*]] = alloca ptr157// LLVM:         store i32 123, ptr %[[I_PTR]]158// LLVM:         store i32 123, ptr %[[J_PTR]]159// LLVM:         store i32 5, ptr %[[I_PTR]]160// LLVM:         %[[GEP1:.*]] = getelementptr i32, ptr %[[ARR_PTR]], i32 0161// LLVM:         %[[GEP2:.*]] = getelementptr i32, ptr %[[GEP1]], i64 5162// LLVM:         %[[ARR_VAL:.*]] = load i32, ptr %[[GEP2]]163// LLVM:         store i32 %[[ARR_VAL]], ptr %[[J_PTR]]164// LLVM:         store ptr null, ptr %[[Q_PTR]]165// LLVM:         br label166// LLVM:         %[[Q_VAL:.*]] = load ptr, ptr %[[Q_PTR]]167// LLVM:         store ptr %[[Q_VAL]], ptr %[[P_PTR]]168// LLVM:         %[[CMP:.*]] = icmp ne ptr %[[Q_VAL]], null169// LLVM:         br i1 %[[CMP]], label %[[THEN:.*]], label %[[ELSE:.*]]170// LLVM:       [[THEN]]:171// LLVM:         store i32 1, ptr %[[RETVAL_PTR]]172// LLVM:         %{{.*}} = load i32, ptr %[[RETVAL_PTR]]173// LLVM:         ret i32174// LLVM:       [[ELSE]]:175// LLVM:         br label176// LLVM:         store i32 0, ptr %[[RETVAL_PTR]]177// LLVM:         %{{.*}} = load i32, ptr %[[RETVAL_PTR]]178// LLVM:         ret i32179 180// OGCG-LABEL: define {{.*}}i32 @ignore_result_assign()181// OGCG:         %[[RETVAL:.*]] = alloca i32182// OGCG:         %[[ARR:.*]] = alloca [10 x i32]183// OGCG:         %[[I:.*]] = alloca i32184// OGCG:         %[[J:.*]] = alloca i32185// OGCG:         %[[P:.*]] = alloca ptr186// OGCG:         %[[Q:.*]] = alloca ptr187// OGCG:         store i32 123, ptr %[[I]]188// OGCG:         store i32 123, ptr %[[J]]189// OGCG:         store i32 5, ptr %[[I]]190// OGCG:         %[[ARRAYIDX:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR]], i64 0, i64 5191// OGCG:         %[[ARR_VAL:.*]] = load i32, ptr %[[ARRAYIDX]]192// OGCG:         store i32 %[[ARR_VAL]], ptr %[[J]]193// OGCG:         store ptr null, ptr %[[Q]]194// OGCG:         %[[Q_VAL:.*]] = load ptr, ptr %[[Q]]195// OGCG:         store ptr %[[Q_VAL]], ptr %[[P]]196// OGCG:         %[[TOBOOL:.*]] = icmp ne ptr %[[Q_VAL]], null197// OGCG:         br i1 %[[TOBOOL]], label %[[IF_THEN:.*]], label %[[IF_END:.*]]198// OGCG:       [[IF_THEN]]:199// OGCG:         store i32 1, ptr %[[RETVAL]]200// OGCG:         br label %[[RETURN:.*]]201// OGCG:       [[IF_END]]:202// OGCG:         store i32 0, ptr %[[RETVAL]]203// OGCG:         br label %[[RETURN]]204// OGCG:       [[RETURN]]:205// OGCG:         %{{.*}} = load i32, ptr %[[RETVAL]]206// OGCG:         ret i32207