brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · 249320f Raw
206 lines · c
1// RUN: %clang_cc1 %s -Wno-pointer-to-int-cast -verify -fsyntax-only -ffreestanding2 3#include <stddef.h>4#include <stdint.h>5 6typedef void (* fp)(void);7void foo(void);8 9// PR clang/337710fp a[(short int)1] = { foo };11 12int myArray[5] = {1, 2, 3, 4, 5};13int *myPointer2 = myArray;14int *myPointer = &(myArray[2]);15 16 17extern int x;18void *g = &x;19int *h = &x;20 21struct union_crash22{23    union24    {25    };26};27 28int test(void) {29  int a[10];30  int b[10] = a; // expected-error {{array initializer must be an initializer list}}31  int +; // expected-error {{expected identifier or '('}}32 33  struct union_crash u = { .d = 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}}34}35 36 37// PR205038struct cdiff_cmd {39          const char *name;40          unsigned short argc;41          int (*handler)(void);42};43int cdiff_cmd_open(void);44struct cdiff_cmd commands[] = {45        {"OPEN", 1, &cdiff_cmd_open }46};47 48// PR234849static struct { int z; } s[2];50int *t = &(*s).z;51 52// PR234953short *a2(void)54{55  short int b;56  static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}57 58  return bp;59}60 61int pbool(void) {62  typedef const _Bool cbool;63  _Bool pbool1 = (void *) 0;64  cbool pbool2 = &pbool;65  return pbool2;66}67 68 69union { float f; unsigned u; } u = { 1.0f };70 71int f3(int x) { return x; }72typedef void (*vfunc)(void);73void *bar = (vfunc) f3;74 75// PR274776struct sym_reg {77        char nc_gpreg;78};79int sym_fw1a_scr[] = {80           ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,81           8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))82};83 84// PR300185struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}}  \86                 // expected-note {{forward declaration of 'struct s1'}}87    .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \88                            // expected-note{{forward declaration of 'struct s3'}}89    .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}90}91 92// PR338293char t[] = ("Hello");94 95typedef struct { } empty;96 97typedef struct {98  empty e;99  int i2;100} st;101 102st st1 = { .i2 = 1 };103 104struct {105  int a;106  int z[2];107} y = { .z = {} };108 109int bbb[10];110 111struct foo2 {112   uintptr_t a;113};114 115struct foo2 bar2[] = {116   { (intptr_t)bbb }117};118 119struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}120#pragma clang diagnostic push121#pragma clang diagnostic ignored "-Wexcess-initializers"122struct foo2 bar3_silent = {1, 2};123#pragma clang diagnostic pop124 125int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);126 127typedef int32_t ivector4 __attribute((vector_size(16)));128ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1};129ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1});130 131uintptr_t ptrasintadd1 = (uintptr_t)&a - 4;132uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;133uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a;134 135// PR4285136const wchar_t widestr[] = L"asdf";137 138// PR5447139const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;140 141// PR4386142 143// None of these are constant initializers, but we implement GCC's old144// behaviour of accepting bar and zed but not foo. GCC's behaviour was145// changed in 2007 (rev 122551), so we should be able to change too one146// day.147int PR4386_bar(void);148int PR4386_foo(void) __attribute((weak));149int PR4386_zed(void);150 151int PR4386_a = ((void *) PR4386_bar) != 0;152int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}153int PR4386_c = ((void *) PR4386_zed) != 0;154int PR4386_zed(void) __attribute((weak));155 156// (derived from SPEC vortex benchmark)157typedef char strty[10];158struct vortexstruct { strty s; };159struct vortexstruct vortexvar = { "asdf" };160 161typedef struct { uintptr_t x : 2; } StructWithBitfield;162StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}}163 164// PR45157165struct PR4517_foo {166  int x;167};168struct PR4517_bar {169  struct PR4517_foo foo;170};171const struct PR4517_foo my_foo = {.x = 42};172struct PR4517_bar my_bar = {173    .foo = my_foo, // no-warning174};175struct PR4517_bar my_bar2 = (struct PR4517_bar){176    .foo = my_foo, // no-warning177};178struct PR4517_bar my_bar3 = {179    my_foo, // no-warning180};181struct PR4517_bar my_bar4 = (struct PR4517_bar){182    my_foo // no-warning183};184extern const struct PR4517_foo my_foo2;185struct PR4517_bar my_bar5 = {186  .foo = my_foo2, // expected-error {{initializer element is not a compile-time constant}}187};188const struct PR4517_foo my_foo3 = {.x = my_foo.x};189int PR4517_a[2] = {0, 1};190const int PR4517_ca[2] = {0, 1};191int PR4517_idx = 0;192const int PR4517_idxc = 1;193int PR4517_x1 = PR4517_a[PR4517_idx]; // expected-error {{initializer element is not a compile-time constant}}194int PR4517_x2 = PR4517_a[PR4517_idxc]; // expected-error {{initializer element is not a compile-time constant}}195int PR4517_x3 = PR4517_a[0]; // expected-error {{initializer element is not a compile-time constant}}196int PR4517_y1 = PR4517_ca[PR4517_idx]; // expected-error {{initializer element is not a compile-time constant}}197int PR4517_y2 = PR4517_ca[PR4517_idxc]; // no-warning198int PR4517_y3 = PR4517_ca[0]; // no-warning199union PR4517_u {200    int x;201    float y;202};203const union PR4517_u u1 = {4.0f};204const union PR4517_u u2 = u1; // no-warning205const union PR4517_u u3 = {u1.y}; // expected-error {{initializer element is not a compile-time constant}}206