| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
|
| 5 |
#ifndef basetype |
| 6 |
#define basetype char |
| 7 |
#endif |
| 8 |
|
| 9 |
#ifndef falseval |
| 10 |
#define falseval 0 |
| 11 |
#endif |
| 12 |
|
| 13 |
#ifndef trueval |
| 14 |
#define trueval ~falseval |
| 15 |
#endif |
| 16 |
|
| 17 |
/* hardbool may be #defined so as to drop parms in other tests. */ |
| 18 |
typedef basetype __attribute__ ((hardbool (falseval, trueval))) hbool; |
| 19 |
|
| 20 |
typedef unsigned char __attribute__ ((__hardbool__ (1, 0))) zbool; |
| 21 |
|
| 22 |
struct hs { |
| 23 |
hbool a[2]; |
| 24 |
hbool x:2; |
| 25 |
hbool y:5; |
| 26 |
zbool z:1; |
| 27 |
}; |
| 28 |
|
| 29 |
hbool var = 0; |
| 30 |
|
| 31 |
struct hs x = { { 1, 0 }, 2, 0, 2 }; |
| 32 |
|
| 33 |
int f(hbool v) { |
| 34 |
return !v; |
| 35 |
} |
| 36 |
|
| 37 |
int g(int i) { |
| 38 |
return f(i); |
| 39 |
} |
| 40 |
|
| 41 |
hbool h(hbool x) { |
| 42 |
return x; |
| 43 |
} |
| 44 |
|
| 45 |
hbool h2(hbool x) { |
| 46 |
return h(x); |
| 47 |
} |
| 48 |
|
| 49 |
int hsx(struct hs v) { |
| 50 |
return v.x; |
| 51 |
} |
| 52 |
|
| 53 |
int ghs(hbool s) { |
| 54 |
struct hs v = { {s, !s}, s, !s, s }; |
| 55 |
return hsx (v); |
| 56 |
} |
| 57 |
|
| 58 |
int t = (hbool)2; |
| 59 |
|
| 60 |
void check_pfalse (hbool *p) |
| 61 |
{ |
| 62 |
assert (!*p); |
| 63 |
assert (*(basetype*)p == (basetype)falseval); |
| 64 |
assert (!(int)(hbool)*p); |
| 65 |
} |
| 66 |
|
| 67 |
void check_ptrue (hbool *p) |
| 68 |
{ |
| 69 |
assert (*p); |
| 70 |
assert (*(basetype*)p == (basetype)trueval); |
| 71 |
assert ((int)(hbool)*p); |
| 72 |
} |
| 73 |
|
| 74 |
void check_vfalse (hbool v) |
| 75 |
{ |
| 76 |
check_pfalse (&v); |
| 77 |
} |
| 78 |
|
| 79 |
void check_vtrue (hbool v) |
| 80 |
{ |
| 81 |
check_ptrue (&v); |
| 82 |
} |
| 83 |
|
| 84 |
int main () { |
| 85 |
check_pfalse (&var); |
| 86 |
var = !(int)(hbool)(_Bool)var; |
| 87 |
check_ptrue (&var); |
| 88 |
var = (zbool)var; |
| 89 |
check_ptrue (&var); |
| 90 |
|
| 91 |
check_ptrue (&x.a[0]); |
| 92 |
check_pfalse (&x.a[1]); |
| 93 |
check_vtrue (x.x); |
| 94 |
check_vfalse (x.y); |
| 95 |
check_vtrue (x.z); |
| 96 |
|
| 97 |
check_vtrue (t); |
| 98 |
|
| 99 |
check_vtrue (var && t); |
| 100 |
check_vfalse (!var || x.y); |
| 101 |
|
| 102 |
check_vfalse (f (2)); |
| 103 |
check_vfalse (f (1)); |
| 104 |
check_vtrue (f (0)); |
| 105 |
|
| 106 |
check_vfalse (g (2)); |
| 107 |
check_vfalse (g (1)); |
| 108 |
check_vtrue (g (0)); |
| 109 |
|
| 110 |
check_vtrue (h (2)); |
| 111 |
check_vtrue (h (1)); |
| 112 |
check_vfalse (h (0)); |
| 113 |
|
| 114 |
check_vtrue (h2 (2)); |
| 115 |
check_vtrue (h2 (1)); |
| 116 |
check_vfalse (h2 (0)); |
| 117 |
} |
| 118 |
|