Compiling the linux kernel with gcc-8 gives this warning: lib/ubsan.c:432:1: error: ignoring attribute 'noreturn' in declaration of a built-in function '__ubsan_handle_builtin_unreachable' because it conflicts with attribute 'const' [-Werror=attributes] It seems that GCC defines __ubsan_handle_builtin_unreachable with noreturn and const attributes: DEF_SANITIZER_BUILTIN(BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE, "__ubsan_handle_builtin_unreachable", BT_FN_VOID_PTR, ATTR_COLD_CONST_NORETURN_NOTHROW_LEAF_LIST) And const doesn't make any sense for function that returns void or doesn't return at all. Shouldn't it be just ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST ?
Confirmed. Note that I'm not sure it makes no sense - it just means the function has no side-effect besides not returning ;) lib/ubsan.c is from the kernel I guess where you "copy" the attributes from sanitizer.def? GCC internally could also use "no vops" but you couldn't replicate that. Not sure if it is/was important to have the function 'const'.
(In reply to Richard Biener from comment #1) > Confirmed. Note that I'm not sure it makes no sense - it just means the > function has no side-effect besides not returning ;) > Well, GCC docs say that const functions "have no effects except to return a value" and "It does not make sense for a const function to return void." I suppose that noreturn functions fells into the same category here as return void functions. Besides, __ubsan_handle_builtin_unreachable() does have side-effect, it prints error. > lib/ubsan.c is from the kernel I guess where you "copy" the attributes from > sanitizer.def? > Yes, lib/ubsan.c is kernel's implementation of libubsan. We don't exactly 'copy' attributes, but __ubsan_handle_builtin_unreachable() does have noreturn. I've tried to add const to be consistent with GCC, but it become only worse: ../lib/ubsan.c:432:1: warning: ignoring attribute ‘noreturn’ in declaration of a built-in function ‘__ubsan_handle_builtin_unreachable’ because it conflicts with attribute ‘const’ [-Wattributes] { ^ <built-in>: note: previous declaration here ../lib/ubsan.c:432:1: warning: ‘const’ attribute on function returning ‘void’ [-Wattributes] ../lib/ubsan.c:432:1: warning: ignoring attribute ‘const’ in declaration of a built-in function ‘__ubsan_handle_builtin_unreachable’ because it conflicts with attribute ‘noreturn’ [-Wattributes] <built-in>: note: previous declaration here > GCC internally could also use "no vops" but you couldn't replicate that. > We probably don't have to replicate all attributes. At least userspace libubsan doesn't do that at all. In fact we could workaround this warning simply by dropping noreturn: http://lkml.kernel.org/r/20180202154813.1625742-1-arnd@arndb.de But, I'm thinking that there is something wrong in GCC, hence filed this bug. > Not sure if it is/was important to have the function 'const'.
The const for the builtin was added by Marek as fix for PR63839. Adding him to CC.
I don't remember if the const was needed. I guess if the testcases added in r217553 still pass even without the const then we can get rid of it.
And then there was an issue where we convert __builtin_unreachable to __builtin_trap which had the similar issue so we added: DEF_GCC_BUILTIN (BUILT_IN_UNREACHABLE_TRAP, "unreachable trap", BT_FN_VOID, ATTR_CONST_NORETURN_NOTHROW_LEAF_COLD_LIST) instead, see PR 107300 for the issue there. So the question becomes why was __builtin_unreachable marked as const, I have no idea. Anyways reconfirmed.