|
| 1 | +// RUN: cconv-standalone -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s |
| 2 | +// RUN: cconv-standalone -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s |
| 3 | +// RUN: cconv-standalone -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - |
| 4 | +// RUN: cconv-standalone -output-postfix=checked -alltypes %s |
| 5 | +// RUN: cconv-standalone -alltypes %S/inline_anon_structs.checked.c -- | count 0 |
| 6 | +// RUN: rm %S/inline_anon_structs.checked.c |
| 7 | + |
| 8 | + |
| 9 | +/*This code ensures conversion happens as expected when |
| 10 | +an inlinestruct and its associated VarDecl have different locations*/ |
| 11 | +int valuable; |
| 12 | + |
| 13 | +static struct foo |
| 14 | +{ |
| 15 | + const char* name; |
| 16 | + //CHECK_NOALL: const char* name; |
| 17 | + //CHECK_ALL: _Ptr<const char> name; |
| 18 | + int* p_valuable; |
| 19 | + //CHECK: _Ptr<int> p_valuable; |
| 20 | +} |
| 21 | +array[] = |
| 22 | +{ |
| 23 | + { "mystery", &valuable } |
| 24 | +}; |
| 25 | + |
| 26 | +/*This code is a series of more complex tests for inline structs*/ |
| 27 | +/* a, b, c below all stay as WILD pointers; d can be a _Ptr<...>*/ |
| 28 | + |
| 29 | + /* one decl; x rewrites to _Ptr<int> */ |
| 30 | +struct foo1 { int *x; } *a; |
| 31 | + //CHECK: struct foo1 { _Ptr<int> x; } *a; |
| 32 | + |
| 33 | +struct baz { int *z; }; |
| 34 | + //CHECK: struct baz { _Ptr<int> z; }; |
| 35 | +struct baz *d; |
| 36 | + //CHECK: _Ptr<struct baz> d = ((void *)0); |
| 37 | + |
| 38 | +struct bad { int* y; } *b, *c; |
| 39 | + //CHECK: struct bad { int* y; } *b, *c; |
| 40 | + |
| 41 | + /* two decls, y should be converted */ |
| 42 | +struct bar { int* y; } *e, *f; |
| 43 | + //CHECK: struct bar { _Ptr<int> y; } *e, *f; |
| 44 | + |
| 45 | + |
| 46 | +void foo(void) { |
| 47 | + a->x = (void*)0; |
| 48 | + b->y = (int *) 5; |
| 49 | + d->z = (void*)0; |
| 50 | +} |
| 51 | + |
| 52 | +/*This code tests anonymous structs */ |
| 53 | +struct { |
| 54 | + /*the fields of the anonymous struct are free to be marked checked*/ |
| 55 | + int *data; |
| 56 | + //CHECK_NOALL: int *data; |
| 57 | + //CHECK_ALL: _Array_ptr<int> data : count(4); |
| 58 | + |
| 59 | +/* but the actual pointer can't be */ |
| 60 | +} *x; |
| 61 | + |
| 62 | +/*ensure trivial conversion*/ |
| 63 | +void foo1(int *w) { |
| 64 | + //CHECK: void foo1(_Ptr<int> w) { |
| 65 | + x->data = malloc(sizeof(int)*4); |
| 66 | + x->data[1] = 4; |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +/*This code tests more complex variable declarations*/ |
| 71 | +struct alpha { |
| 72 | + int *data; |
| 73 | + //CHECK: _Ptr<int> data; |
| 74 | +}; |
| 75 | +struct alpha *al[4]; |
| 76 | + //CHECK_NOALL: struct alpha *al[4]; |
| 77 | + //CHECK_ALL: _Ptr<struct alpha> al _Checked[4]; |
| 78 | + |
| 79 | +/*be should be made wild, whereas a should be converted*/ |
| 80 | +struct { |
| 81 | + int *a; |
| 82 | + //CHECK: _Ptr<int> a; |
| 83 | +} *be[4]; |
| 84 | + |
| 85 | +/*this code checks inline structs withiin functions*/ |
| 86 | +void foo2(int *x) { |
| 87 | + //CHECK: void foo2(_Ptr<int> x) { |
| 88 | + struct bar { int *x; } *y = 0; |
| 89 | + //CHECK: struct bar { _Ptr<int> x; } *y = 0; |
| 90 | + |
| 91 | + /*A non-pointer struct without an init will be marked wild*/ |
| 92 | + struct something { int *x; } z; |
| 93 | + //CHECK: struct something { int *x; } z; |
| 94 | + |
| 95 | + /*so will ones that are anonymous*/ |
| 96 | + struct { int *x; } a; |
| 97 | + //CHECK: struct { int *x; } a; |
| 98 | + |
| 99 | + /*if it have an initializer, the rewriter won't have trouble*/ |
| 100 | + struct { int * c; } b = {}; |
| 101 | + //CHECK: struct { _Ptr<int> c; } b = {}; |
| 102 | +} |
| 103 | + |
| 104 | + |
0 commit comments