brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · 93015da Raw
213 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -Wno-strict-prototypes -emit-llvm -o - | FileCheck %s2 3// PR18954// sizeof function5int zxcv(void);6int x=sizeof(zxcv);7int y=__alignof__(zxcv);8 9 10void test(int *i) {11 short a = 1;12 i += a;13 i + a;14 a + i;15}16 17_Bool test2b; 18int test2(void) { if (test2b); return 0; }19 20// PR192121void test3(void) {22  const unsigned char *bp;23  bp -= (short)1;24}25 26// PR2080 - sizeof void27int t1 = sizeof(void);28int t2 = __alignof__(void);29void test4(void) {30  t1 = sizeof(void);31  t2 = __alignof__(void);32  33  t1 = sizeof(test4());34  t2 = __alignof__(test4());35}36 37// 'const float' promotes to double in varargs.38int test5(const float x, float float_number) {39  return __builtin_isless(x, float_number);40}41 42// this one shouldn't fold43int ola(void) {44  int a=2;45  if ((0, (int)a) & 2) { return 1; }46  return 2;47}48 49// this one shouldn't fold as well50void eMaisUma(void) {51  double t[1];52  if (*t)53    return;54}55 56void f0(void (*fp)(void), void (*fp2)(void)) {57  int x = fp - fp2;58}59 60// noop casts as lvalues.61struct X {62  int Y;63};64struct X foo();65int bar(void) {66  return ((struct X)foo()).Y + 1;67}68 69// PR3809: INC/DEC of function pointers.70void f2(void);71unsigned f1(void) {72  void (*fp)(void) = f2;73  74  ++fp;75  fp++;76  --fp;77  fp--;78  return (unsigned) fp;79}  80 81union f3_x {int x; float y;};82int f3(void) {return ((union f3_x)2).x;}83 84union f4_y {int x; _Complex float y;};85_Complex float f4(void) {return ((union f4_y)(_Complex float)2.0).y;}86 87struct f5_a { int a; } f5_a;88union f5_z {int x; struct f5_a y;};89struct f5_a f5(void) {return ((union f5_z)f5_a).y;}90 91// ?: in "lvalue"92struct s6 { int f0; };93int f6(int a0, struct s6 a1, struct s6 a2) {94  return (a0 ? a1 : a2).f0;95}96 97// PR402698void f7(void) {99  __func__;100}101 102// PR4067103int f8(void) {104  return ({ foo(); }).Y;105}106 107struct S;108struct C {109  int i;110  struct S *tab[];111};112struct S { struct C c; };113void f9(struct S *x) {114  foo(((void)1, x->c).tab[0]);115}116 117void f10(void) {118  __builtin_sin(0);119}120 121// CHECK-LABEL: define{{.*}} i32 @f11122int f11(long X) {123  int A[100];124  return A[X];125 126// CHECK: [[Xaddr:%[^ ]+]] = alloca i64, align 8127// CHECK: [[A:%.*]] = alloca [100 x i32], align128// CHECK: [[X:%.*]] = load {{.*}}, ptr [[Xaddr]]129// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [100 x i32], ptr [[A]], i64 0, i64 [[X]]130// CHECK-NEXT: load i32, ptr [[T0]], align 4131}132 133int f12(void) {134  // PR3150135  // CHECK-LABEL: define{{.*}} i32 @f12136  // CHECK: ret i32 1137  return 1||1;138}139 140// Make sure negate of fp uses -0.0 for proper -0 handling.141double f13(double X) {142  // CHECK-LABEL: define{{.*}} double @f13143  // CHECK: fneg double144  return -X;145}146 147// Check operations on incomplete types.148void f14(struct s14 *a) {149  (void) &*a;150}151 152// CHECK-LABEL: define{{.*}} void @f15153void f15(void) {154  extern void f15_start(void);155  f15_start();156  // CHECK: call void @f15_start()157 158  extern void *f15_v(void);159  extern const void *f15_cv(void);160  extern volatile void *f15_vv(void);161  *f15_v(); *f15_v(), *f15_v(); f15_v() ? *f15_v() : *f15_v();162  *f15_cv(); *f15_cv(), *f15_cv(); f15_cv() ? *f15_cv() : *f15_cv();163  *f15_vv(); *f15_vv(), *f15_vv(); f15_vv() ? *f15_vv() : *f15_vv();164  // CHECK-NOT: load165  // CHECK: ret void166}167 168// PR8967: this was crashing169// CHECK-LABEL: define{{.*}} void @f16()170void f16(void) {171  __extension__({ goto lbl; });172 lbl:173  ;174}175 176// PR13704: negative increment in i128 is not preserved.177// CHECK-LABEL: define{{.*}} void @f17()178void f17(void) {179  extern void extfunc(__int128);180  __int128 x = 2;181  x--;182  extfunc(x);183// CHECK: add nsw i128 %{{.}}, -1184}185 186// PR23597: We should evaluate union cast operands even if the cast is unused.187typedef union u {188    int i;189} strct;190int returns_int(void);191void f18(void) {192  (strct)returns_int();193}194// CHECK-LABEL: define{{.*}} void @f18()195// CHECK: call i32 @returns_int()196 197// Ensure the right stmt is returned198int f19(void) {199  return ({ 3;;4; });200}201// CHECK-LABEL: define{{.*}} i32 @f19()202// CHECK: [[T:%.*]] = alloca i32203// CHECK: store i32 4, ptr [[T]]204// CHECK: [[L:%.*]] = load i32, ptr [[T]]205// CHECK: ret i32 [[L]]206 207// PR166036: The trailing NullStmt should result in a void.208void f20(void) {209  return ({ 3;;4;; });210}211// CHECK-LABEL: define{{.*}} void @f20()212// CHECK: ret void213