1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-10 05:18:17 +03:00

tests: skip static asserts on old clang versions

We declare clang >= 10 is supported. The workaround is easy enough, so let's
just do that. Fixes #28598. With Debian clang version 11.0.1-2:

[267/384] Compiling C object test-bitfield.p/src_test_test-bitfield.c.o
FAILED: test-bitfield.p/src_test_test-bitfield.c.o
clang -Itest-bitfield.p -I. -I.. -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/shared -I../src/shared -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wno-missing-field-initializers -Wno-unused-parameter -Warray-bounds -Wdate-time -Wendif-labels -Werror=format=2 -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=missing-declarations -Werror=missing-prototypes -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=undef -Wfloat-equal -Winit-self -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wunused-function -Wwrite-strings '-Wno-error=#warnings' -Wno-string-plus-int -fdiagnostics-show-option -fno-common -fstack-protector -fstack-protector-strong --param=ssp-buffer-size=4 -Wno-typedef-redefinition -Wno-gnu-variable-sized-type-not-at-end -Werror=shadow -fno-strict-aliasing -fvisibility=hidden -fno-omit-frame-pointer -include config.h -DTEST_CODE=1 -MD -MQ test-bitfield.p/src_test_test-bitfield.c.o -MF test-bitfield.p/src_test_test-bitfield.c.o.d -o test-bitfield.p/src_test_test-bitfield.c.o -c ../src/test/test-bitfield.c
../src/test/test-bitfield.c:216:9: error: static_assert failed due to requirement '__builtin_constant_p(({
    static_assert(sizeof(unsigned char) <= sizeof(unsigned long long), "sizeof(uint8_t) <= sizeof(unsigned long long)");
    static_assert(__builtin_choose_expr(__builtin_constant_p(1), 1, 0) < (int)(sizeof(unsigned char) * 8), "__builtin_choose_expr(__builtin_constant_p(1), 1, 0) < (int)(sizeof(uint8_t) * 8)");
    __builtin_choose_expr(__builtin_constant_p(1), ((unsigned char)1) << (1), ({
        int __unique_prefix__i751 = (1);
        do {
            if ((__builtin_expect(!!(!(__unique_prefix__i751 < (int)sizeof(unsigned char) * 8)), 0)))
                log_assert_failed("UNIQ_T(_i, 751) < (int)sizeof(uint8_t) * 8", (&"../src/test/test-bitfield.c"[(sizeof ("..") - sizeof(const char)) + 1]), 216, __func__);
        } while (0);
        ((unsigned char)1) << __unique_prefix__i751;
    }));
}))' "__builtin_constant_p(INDEX_TO_MASK(uint8_t, 1))"
        assert_cc(__builtin_constant_p(INDEX_TO_MASK(uint8_t, 1)));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/fundamental/macro-fundamental.h:109:25: note: expanded from macro 'assert_cc'
                        ^             ~~~~
/usr/include/assert.h:143:24: note: expanded from macro 'static_assert'
                       ^
...
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-07-31 14:12:36 +02:00
parent 7f4b3dc043
commit 6425dec88b

View File

@ -213,6 +213,8 @@ TEST(bits) {
assert_se(_u64 == u64);
/* Verify these use cases are constant-folded. */
#if !defined(__clang__) || (__clang_major__ >= 13)
/* Clang 11 doesn't grok those; skip them. */
assert_cc(__builtin_constant_p(INDEX_TO_MASK(uint8_t, 1)));
assert_cc(__builtin_constant_p(INDEX_TO_MASK(uint16_t, 1)));
assert_cc(__builtin_constant_p(INDEX_TO_MASK(uint32_t, 1)));
@ -222,6 +224,7 @@ TEST(bits) {
assert_cc(__builtin_constant_p(BIT_SET((uint16_t)2, 1)));
assert_cc(__builtin_constant_p(BIT_SET((uint32_t)2, 1)));
assert_cc(__builtin_constant_p(BIT_SET((uint64_t)2, 1)));
#endif
}
DEFINE_TEST_MAIN(LOG_INFO);