brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.0 KiB · 74229fd Raw
318 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR --check-prefix=CIR-NO-STRICT3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -emit-llvm -disable-llvm-passes %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM --check-prefix=LLVM-NO-STRICT5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -emit-llvm -disable-llvm-passes %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG --check-prefix=OGCG-NO-STRICT7 8// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=0 -emit-cir %s -o %t-strict-0.cir9// RUN: FileCheck --input-file=%t-strict-0.cir %s --check-prefix=CIR --check-prefix=CIR-STRICT-010// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=0 -emit-llvm -disable-llvm-passes %s -o %t-cir-strict-0.ll11// RUN: FileCheck --input-file=%t-cir-strict-0.ll %s --check-prefix=LLVM --check-prefix=LLVM-STRICT-012// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fstrict-flex-arrays=0 -emit-llvm -disable-llvm-passes %s -o %t-strict-0.ll13// RUN: FileCheck --input-file=%t-strict-0.ll %s --check-prefix=OGCG --check-prefix=OGCG-STRICT-014 15// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=1 -emit-cir %s -o %t-strict-1.cir16// RUN: FileCheck --input-file=%t-strict-1.cir %s --check-prefix=CIR --check-prefix=CIR-STRICT-117// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=1 -emit-llvm -disable-llvm-passes %s -o %t-cir-strict-1.ll18// RUN: FileCheck --input-file=%t-cir-strict-1.ll %s --check-prefix=LLVM --check-prefix=LLVM-STRICT-119// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fstrict-flex-arrays=1 -emit-llvm -disable-llvm-passes %s -o %t-strict-1.ll20// RUN: FileCheck --input-file=%t-strict-1.ll %s --check-prefix=OGCG --check-prefix=OGCG-STRICT-121 22// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=2 -emit-cir %s -o %t-strict-2.cir23// RUN: FileCheck --input-file=%t-strict-2.cir %s --check-prefix=CIR --check-prefix=CIR-STRICT-224// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=2 -emit-llvm -disable-llvm-passes %s -o %t-cir-strict-2.ll25// RUN: FileCheck --input-file=%t-cir-strict-2.ll %s --check-prefix=LLVM --check-prefix=LLVM-STRICT-226// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fstrict-flex-arrays=2 -emit-llvm -disable-llvm-passes %s -o %t-strict-2.ll27// RUN: FileCheck --input-file=%t-strict-2.ll %s --check-prefix=OGCG --check-prefix=OGCG-STRICT-228 29// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=3 -emit-cir %s -o %t-strict-3.cir30// RUN: FileCheck --input-file=%t-strict-3.cir %s --check-prefix=CIR --check-prefix=CIR-STRICT-331// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -fstrict-flex-arrays=3 -emit-llvm -disable-llvm-passes %s -o %t-cir-strict-3.ll32// RUN: FileCheck --input-file=%t-cir-strict-3.ll %s --check-prefix=LLVM --check-prefix=LLVM-STRICT-333// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fstrict-flex-arrays=3 -emit-llvm -disable-llvm-passes %s -o %t-strict-3.ll34// RUN: FileCheck --input-file=%t-strict-3.ll %s --check-prefix=OGCG --check-prefix=OGCG-STRICT-335 36#define OBJECT_SIZE_BUILTIN __builtin_object_size37 38typedef struct {39  float f;40  double c[];41} foo_t;42 43typedef struct {44  float f;45  double c[0];46} foo0_t;47 48typedef struct {49  float f;50  double c[1];51} foo1_t;52 53typedef struct {54  float f;55  double c[2];56} foo2_t;57 58// CIR-LABEL: @bar59// LLVM-LABEL: @bar(60// OGCG-LABEL: @bar(61unsigned bar(foo_t *f) {62  // CIR-NO-STRICT: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i63  // CIR-STRICT-0: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i64  // CIR-STRICT-1: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i65  // CIR-STRICT-2: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i66  // CIR-STRICT-3: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i67  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)68  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)69  // LLVM-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)70  // LLVM-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)71  // LLVM-STRICT-3: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)72  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)73  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)74  // OGCG-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)75  // OGCG-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)76  // OGCG-STRICT-3: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)77  return OBJECT_SIZE_BUILTIN(f->c, 1);78}79 80// CIR-LABEL: @bar081// LLVM-LABEL: @bar0(82// OGCG-LABEL: @bar0(83unsigned bar0(foo0_t *f) {84  // CIR-NO-STRICT: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i85  // CIR-STRICT-0: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i86  // CIR-STRICT-1: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i87  // CIR-STRICT-2: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i88  // CIR-STRICT-3: cir.const #cir.int<0>89  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)90  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)91  // LLVM-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)92  // LLVM-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)93  // LLVM-STRICT-3: store i32 094  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)95  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)96  // OGCG-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)97  // OGCG-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)98  // OGCG-STRICT-3: ret i32 099  return OBJECT_SIZE_BUILTIN(f->c, 1);100}101 102// CIR-LABEL: @bar1103// LLVM-LABEL: @bar1(104// OGCG-LABEL: @bar1(105unsigned bar1(foo1_t *f) {106  // CIR-NO-STRICT: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i107  // CIR-STRICT-0: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i108  // CIR-STRICT-1: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i109  // CIR-STRICT-2: cir.const #cir.int<8>110  // CIR-STRICT-3: cir.const #cir.int<8>111  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)112  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)113  // LLVM-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)114  // LLVM-STRICT-2: store i32 8115  // LLVM-STRICT-3: store i32 8116  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)117  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)118  // OGCG-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)119  // OGCG-STRICT-2: ret i32 8120  // OGCG-STRICT-3: ret i32 8121  return OBJECT_SIZE_BUILTIN(f->c, 1);122}123 124// CIR-LABEL: @bar2125// LLVM-LABEL: @bar2(126// OGCG-LABEL: @bar2(127unsigned bar2(foo2_t *f) {128  // CIR-NO-STRICT: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i129  // CIR-STRICT-0: cir.objsize max nullunknown {{.*}} : !cir.ptr<!void> -> !u64i130  // CIR-STRICT-1: cir.const #cir.int<16>131  // CIR-STRICT-2: cir.const #cir.int<16>132  // CIR-STRICT-3: cir.const #cir.int<16>133  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)134  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)135  // LLVM-STRICT-1: store i32 16136  // LLVM-STRICT-2: store i32 16137  // LLVM-STRICT-3: store i32 16138  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)139  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 false)140  // OGCG-STRICT-1: ret i32 16141  // OGCG-STRICT-2: ret i32 16142  // OGCG-STRICT-3: ret i32 16143  return OBJECT_SIZE_BUILTIN(f->c, 1);144}145 146#define DYNAMIC_OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size147 148// CIR-LABEL: @dyn_bar149// LLVM-LABEL: @dyn_bar(150// OGCG-LABEL: @dyn_bar(151unsigned dyn_bar(foo_t *f) {152  // CIR-NO-STRICT: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i153  // CIR-STRICT-0: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i154  // CIR-STRICT-1: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i155  // CIR-STRICT-2: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i156  // CIR-STRICT-3: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i157  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)158  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)159  // LLVM-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)160  // LLVM-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)161  // LLVM-STRICT-3: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)162  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)163  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)164  // OGCG-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)165  // OGCG-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)166  // OGCG-STRICT-3: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)167  return DYNAMIC_OBJECT_SIZE_BUILTIN(f->c, 1);168}169 170// CIR-LABEL: @dyn_bar0171// LLVM-LABEL: @dyn_bar0(172// OGCG-LABEL: @dyn_bar0(173unsigned dyn_bar0(foo0_t *f) {174  // CIR-NO-STRICT: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i175  // CIR-STRICT-0: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i176  // CIR-STRICT-1: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i177  // CIR-STRICT-2: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i178  // CIR-STRICT-3: cir.const #cir.int<0>179  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)180  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)181  // LLVM-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)182  // LLVM-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)183  // LLVM-STRICT-3: store i32 0184  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)185  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)186  // OGCG-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)187  // OGCG-STRICT-2: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)188  // OGCG-STRICT-3: ret i32 0189  return DYNAMIC_OBJECT_SIZE_BUILTIN(f->c, 1);190}191 192// CIR-LABEL: @dyn_bar1193// LLVM-LABEL: @dyn_bar1(194// OGCG-LABEL: @dyn_bar1(195unsigned dyn_bar1(foo1_t *f) {196  // CIR-NO-STRICT: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i197  // CIR-STRICT-0: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i198  // CIR-STRICT-1: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i199  // CIR-STRICT-2: cir.const #cir.int<8>200  // CIR-STRICT-3: cir.const #cir.int<8>201  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)202  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)203  // LLVM-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)204  // LLVM-STRICT-2: store i32 8205  // LLVM-STRICT-3: store i32 8206  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)207  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)208  // OGCG-STRICT-1: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)209  // OGCG-STRICT-2: ret i32 8210  // OGCG-STRICT-3: ret i32 8211  return DYNAMIC_OBJECT_SIZE_BUILTIN(f->c, 1);212}213 214// CIR-LABEL: @dyn_bar2215// LLVM-LABEL: @dyn_bar2(216// OGCG-LABEL: @dyn_bar2(217unsigned dyn_bar2(foo2_t *f) {218  // CIR-NO-STRICT: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i219  // CIR-STRICT-0: cir.objsize max nullunknown dynamic {{.*}} : !cir.ptr<!void> -> !u64i220  // CIR-STRICT-1: cir.const #cir.int<16>221  // CIR-STRICT-2: cir.const #cir.int<16>222  // CIR-STRICT-3: cir.const #cir.int<16>223  // LLVM-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)224  // LLVM-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)225  // LLVM-STRICT-1: store i32 16226  // LLVM-STRICT-2: store i32 16227  // LLVM-STRICT-3: store i32 16228  // OGCG-NO-STRICT: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)229  // OGCG-STRICT-0: llvm.objectsize.i64.p0(ptr {{.*}}, i1 false, i1 true, i1 true)230  // OGCG-STRICT-1: ret i32 16231  // OGCG-STRICT-2: ret i32 16232  // OGCG-STRICT-3: ret i32 16233  return DYNAMIC_OBJECT_SIZE_BUILTIN(f->c, 1);234}235 236// Also checks for non-trailing flex-array like members237 238typedef struct {239  double c[0];240  float f;241} foofoo0_t;242 243typedef struct {244  double c[1];245  float f;246} foofoo1_t;247 248typedef struct {249  double c[2];250  float f;251} foofoo2_t;252 253// CIR-LABEL: @babar0254// LLVM-LABEL: @babar0(255// OGCG-LABEL: @babar0(256unsigned babar0(foofoo0_t *f) {257  // CIR-NO-STRICT: cir.const #cir.int<0>258  // CIR-STRICT-0: cir.const #cir.int<0>259  // CIR-STRICT-1: cir.const #cir.int<0>260  // CIR-STRICT-2: cir.const #cir.int<0>261  // CIR-STRICT-3: cir.const #cir.int<0>262  // LLVM-NO-STRICT: store i32 0263  // LLVM-STRICT-0: store i32 0264  // LLVM-STRICT-1: store i32 0265  // LLVM-STRICT-2: store i32 0266  // LLVM-STRICT-3: store i32 0267  // OGCG-NO-STRICT: ret i32 0268  // OGCG-STRICT-0: ret i32 0269  // OGCG-STRICT-1: ret i32 0270  // OGCG-STRICT-2: ret i32 0271  // OGCG-STRICT-3: ret i32 0272  return OBJECT_SIZE_BUILTIN(f->c, 1);273}274 275// CIR-LABEL: @babar1276// LLVM-LABEL: @babar1(277// OGCG-LABEL: @babar1(278unsigned babar1(foofoo1_t *f) {279  // CIR-NO-STRICT: cir.const #cir.int<8>280  // CIR-STRICT-0: cir.const #cir.int<8>281  // CIR-STRICT-1: cir.const #cir.int<8>282  // CIR-STRICT-2: cir.const #cir.int<8>283  // CIR-STRICT-3: cir.const #cir.int<8>284  // LLVM-NO-STRICT: store i32 8285  // LLVM-STRICT-0: store i32 8286  // LLVM-STRICT-1: store i32 8287  // LLVM-STRICT-2: store i32 8288  // LLVM-STRICT-3: store i32 8289  // OGCG-NO-STRICT: ret i32 8290  // OGCG-STRICT-0: ret i32 8291  // OGCG-STRICT-1: ret i32 8292  // OGCG-STRICT-2: ret i32 8293  // OGCG-STRICT-3: ret i32 8294  return OBJECT_SIZE_BUILTIN(f->c, 1);295}296 297// CIR-LABEL: @babar2298// LLVM-LABEL: @babar2(299// OGCG-LABEL: @babar2(300unsigned babar2(foofoo2_t *f) {301  // CIR-NO-STRICT: cir.const #cir.int<16>302  // CIR-STRICT-0: cir.const #cir.int<16>303  // CIR-STRICT-1: cir.const #cir.int<16>304  // CIR-STRICT-2: cir.const #cir.int<16>305  // CIR-STRICT-3: cir.const #cir.int<16>306  // LLVM-NO-STRICT: store i32 16307  // LLVM-STRICT-0: store i32 16308  // LLVM-STRICT-1: store i32 16309  // LLVM-STRICT-2: store i32 16310  // LLVM-STRICT-3: store i32 16311  // OGCG-NO-STRICT: ret i32 16312  // OGCG-STRICT-0: ret i32 16313  // OGCG-STRICT-1: ret i32 16314  // OGCG-STRICT-2: ret i32 16315  // OGCG-STRICT-3: ret i32 16316  return OBJECT_SIZE_BUILTIN(f->c, 1);317}318