diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/enum-fixed.c | 36 | ||||
-rw-r--r-- | test/enum-fixed.qbe | 0 | ||||
-rw-r--r-- | test/enum-large-value.c | 68 | ||||
-rw-r--r-- | test/enum-large-value.qbe | 1 |
4 files changed, 101 insertions, 4 deletions
diff --git a/test/enum-fixed.c b/test/enum-fixed.c new file mode 100644 index 0000000..9ac85ca --- /dev/null +++ b/test/enum-fixed.c @@ -0,0 +1,36 @@ +enum E1 : short; +_Static_assert(__builtin_types_compatible_p(enum E1, short)); + +enum E2 : unsigned short { + A2 = 0x7fff, + B2, + A2type = __builtin_types_compatible_p(typeof(A2), unsigned short), + B2type = __builtin_types_compatible_p(typeof(B2), unsigned short), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A2), unsigned short)); +_Static_assert(A2type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B2), unsigned short)); +_Static_assert(B2type == 1); +_Static_assert(__builtin_types_compatible_p(enum E2, unsigned short)); + +enum E3 : long long { + A3, + B3, + A3type = __builtin_types_compatible_p(typeof(A3), long long), + B3type = __builtin_types_compatible_p(typeof(B3), long long), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A3), long long)); +_Static_assert(A3type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B3), long long)); +_Static_assert(B3type == 1); +_Static_assert(__builtin_types_compatible_p(enum E3, long long)); + +enum E4 : long long { + A4 = sizeof(enum E4), + A4type1 = __builtin_types_compatible_p(typeof(A4), enum E4), + A4type2 = !__builtin_types_compatible_p(typeof(A4), enum E3), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A4), enum E4)); +_Static_assert(A4type1 == 1); +_Static_assert(!__builtin_types_compatible_p(typeof(A4), enum E3)); +_Static_assert(A4type2 == 1); diff --git a/test/enum-fixed.qbe b/test/enum-fixed.qbe new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/enum-fixed.qbe diff --git a/test/enum-large-value.c b/test/enum-large-value.c index 3532062..075021c 100644 --- a/test/enum-large-value.c +++ b/test/enum-large-value.c @@ -1,4 +1,66 @@ -enum { - A = 0x80000000, +enum E1 { + A1 = 0x80000000, + B1 = 0x80000000ll, + A1type = __builtin_types_compatible_p(typeof(A1), unsigned), + B1type = __builtin_types_compatible_p(typeof(B1), long long), }; -int x = A < 0; +_Static_assert(__builtin_types_compatible_p(typeof(A1), unsigned)); +_Static_assert(A1type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B1), unsigned)); +_Static_assert(B1type == 1); +_Static_assert(__builtin_types_compatible_p(enum E1, unsigned)); +_Static_assert(!__builtin_types_compatible_p(enum E1, enum { A1_ = A1, B1_ = B1 })); + +enum E2 { + A2 = 0x80000000, + B2 = -1ll, + A2type = __builtin_types_compatible_p(typeof(A2), unsigned), + B2type = __builtin_types_compatible_p(typeof(B2), int), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A2), long)); +_Static_assert(A2type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B2), long)); +_Static_assert(B2type == 1); +_Static_assert(__builtin_types_compatible_p(enum E2, long)); +_Static_assert(!__builtin_types_compatible_p(enum E2, enum { A2_ = A2, B2_ = B2 })); + +enum E3 { + A3 = 0x7fffffff, + B3, + A3type = __builtin_types_compatible_p(typeof(A3), int), + B3type = __builtin_types_compatible_p(typeof(B3), long), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A3), unsigned)); +_Static_assert(A3type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B3), unsigned)); +_Static_assert(B3type == 1); +_Static_assert(__builtin_types_compatible_p(enum E3, unsigned)); +_Static_assert(!__builtin_types_compatible_p(enum E3, enum { A3_ = A3, B3_ })); + +enum E4 { + A4 = -0x80000001l, + B4, + C4 = B4, + A4type = __builtin_types_compatible_p(typeof(A4), long), + B4type = __builtin_types_compatible_p(typeof(B4), long), + C4type = __builtin_types_compatible_p(typeof(C4), int), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A4), long)); +_Static_assert(A4type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B4), long)); +_Static_assert(B4type == 1); +_Static_assert(__builtin_types_compatible_p(enum E4, long)); +_Static_assert(!__builtin_types_compatible_p(enum E4, enum { A4_ = A4, B4_, C4 = C4 })); + +enum E5 { + A5 = 0x100000000, + B5 = -1ull, + A5type = __builtin_types_compatible_p(typeof(A5), long), + B5type = __builtin_types_compatible_p(typeof(B5), unsigned long long), +}; +_Static_assert(__builtin_types_compatible_p(typeof(A5), unsigned long)); +_Static_assert(A5type == 1); +_Static_assert(__builtin_types_compatible_p(typeof(B5), unsigned long)); +_Static_assert(B5type == 1); +_Static_assert(__builtin_types_compatible_p(enum E5, unsigned long)); +_Static_assert(!__builtin_types_compatible_p(enum E5, enum { A5_ = A5, B5_ = B5 })); diff --git a/test/enum-large-value.qbe b/test/enum-large-value.qbe index a67781d..e69de29 100644 --- a/test/enum-large-value.qbe +++ b/test/enum-large-value.qbe @@ -1 +0,0 @@ -export data $x = align 4 { w 0, } |