https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105727

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Jan Hubicka from comment #6)
> I don't know what clang does, but GCC keeps builtin_constant_p till late
> optimization and resolves it then. So here we cross module inline (or
> constant propagate) and then it becomes constant.
> 
> Outcome of __builtin_constant_p should depend on optimization settings and
> LTO is one of them. So I would say that both clang and gcc are correct, just
> gcc has better QOI.  Why this breaks kernel?

Using KASAN, we end up with:

In function ‘memory_is_poisoned’,
    inlined from ‘check_region_inline’ at mm/kasan/generic.c:180:6,
    inlined from ‘kasan_check_range’ at mm/kasan/generic.c:189:9,
    inlined from ‘memset’ at mm/kasan/shadow.c:44:7,
    inlined from ‘do_sysinfo.isra’ at kernel/sys.c:2656:2:
mm/kasan/generic.c:155:25: error: call to ‘__compiletime_assert_243’ declared
with attribute error: BUILD_BUG failed
  155 |                         BUILD_BUG();


static __always_inline bool memory_is_poisoned(unsigned long addr, size_t size)
{
        if (__builtin_constant_p(size)) {
                switch (size) {
                case 1:
                        return memory_is_poisoned_1(addr);
                case 2:
                case 4:
                case 8:
                        return memory_is_poisoned_2_4_8(addr, size);
                case 16:
                        return memory_is_poisoned_16(addr);
                default:
                        BUILD_BUG();
                }
        }

        return memory_is_poisoned_n(addr, size);
}

where we propagate large some value during LTRANS and that's why we end up with
BUILD_BUG().

Reply via email to