On Thu, Feb 25, 2021 at 10:23 PM 'Nick Desaulniers' via Clang Built Linux <clang-built-li...@googlegroups.com> wrote: > > On Thu, Feb 25, 2021 at 8:45 AM Mathieu Poirier > <mathieu.poir...@linaro.org> wrote: > > > > Good morning, > > > > On Thu, Feb 25, 2021 at 10:42:58AM +0100, Arnd Bergmann wrote: > > > From: Arnd Bergmann <a...@arndb.de> > > > > > > clang-12 fails to build the etm4x driver with -fsanitize=array-bounds: > > Is a sanitizer enabled, that would trap on OOB? > > > > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/1310
As described over there, this happens only with the array-bounds sanitizer. Actually, looking at it again now, in the reduced test case, the inline assembly is not even parsable, it only works because it never gets emitted without -fsanitize=array-bounds, and the alternative code path is used in #define read_etm4x_sysreg_offset(offset, _64bit) \ ({ \ u64 __val; \ \ if (__builtin_constant_p((offset))) \ __val = read_etm4x_sysreg_const_offset((offset)); \ else \ __val = etm4x_sysreg_read((offset), true, (_64bit)); \ __val; \ }) read_etm4x_sysreg_const_offset() eventually turns into something like asm("msr_s " __stringify(offset)); so the offset has to be something that can be parsed by the assembler. __builtin_constant_p() checks that it is a constant value at compile-time, and in this case it can be because there is a small upper bound and clang just unrolls the loop. I don't think there is an alternative to __builtin_constant_p() that can be used to decide if the argument is something that can be used as a constant expression in an inline assembly. Arnd