32 lines · c
1// RUN: %clang_cc1 -verify -std=c89 %s2// RUN: %clang_cc1 -verify -std=c99 %s3// RUN: %clang_cc1 -verify -std=c11 %s4// RUN: %clang_cc1 -verify -std=c17 %s5// RUN: %clang_cc1 -verify -std=c23 %s6// expected-no-diagnostics7 8/* WG14 N1310: Yes9 * Requiring signed char to have no padding bits10 */11 12/* This is shockingly hard to test, but we're trying our best by checking that13 * setting each bit of an unsigned char, then bit-casting it to signed char,14 * results in a value we expect to see. If we have padding bits, then it's15 * possible (but not mandatory) for the value to not be as we expect, so a16 * failing assertion means the implementation is broken but a passing test does17 * not *prove* there aren't padding bits.18 */19_Static_assert(__CHAR_BIT__ == 8, "");20_Static_assert(sizeof(signed char) == 1, "");21 22#define TEST(Bit, Expected) __builtin_bit_cast(signed char, (unsigned char)(1 << Bit)) == Expected23_Static_assert(TEST(0, 1), "");24_Static_assert(TEST(1, 2), "");25_Static_assert(TEST(2, 4), "");26_Static_assert(TEST(3, 8), "");27_Static_assert(TEST(4, 16), "");28_Static_assert(TEST(5, 32), "");29_Static_assert(TEST(6, 64), "");30_Static_assert(TEST(7, (signed char)128), "");31 32