]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Rewrite IN_SET() 13093/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 11 Jul 2019 08:17:28 +0000 (10:17 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 17 Jul 2019 12:22:53 +0000 (14:22 +0200)
This restores proper speed with asan builds with gcc 9.1.1.
Fixes #12997.

$ rpm -q gcc
gcc-9.1.1-2.fc31.x86_64

$ time ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1 build-rawhide-sanitize/test-conf-parser

(old) 86.99s user 20.22s system 361% cpu 29.635 total
(new)  3.05s user  0.29s system  99% cpu  3.377 total

Size is increased a bit:

$ size build/systemd
(old) 1683421  246100    1208 1930729  1d75e9 build/systemd
(new) 1688237  246100    1208 1935545  1d88b9 build/systemd

... but that's <0.1%, so we don't really care.

src/basic/macro.h

index 00dfd480239bb9e60444e5ddec1843771672eba1..336cb3a099920de3bb32b3b95782ce73fa6f0aa8 100644 (file)
@@ -462,7 +462,8 @@ static inline int __coverity_check__(int condition) {
                  * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \
                  * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that  \
                  * doesn't work, as we want to use this on bitfields and gcc refuses typeof() on bitfields.) */         \
-                assert_cc((sizeof((long double[]){__VA_ARGS__})/sizeof(long double)) <= 20); \
+                static const long double __assert_in_set[] _unused_ = { __VA_ARGS__ }; \
+                assert_cc(ELEMENTSOF(__assert_in_set) <= 20); \
                 switch(x) {                     \
                 FOR_EACH_MAKE_CASE(__VA_ARGS__) \
                         _found = true;          \