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

            Bug ID: 121731
           Summary: "not a constant expression" compile error when ubsan
                    enabled, compiles fine on clang
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carlosgalvezp at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---

Created attachment 62250
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62250&action=edit
Reduced example

Hi,

We are hitting a compiler error when building on GCC trunk and UBSAN enabled,
please find the attached reduced example (apologies for the lack of
readability, it comes straight out of creduce :)).

Compiling with:

$ g++ -fsanitize=undefined -c test.ii

Gives:

test.ii:5:49: error: ‘(((const int*)(& da::dd.bk<int, b<1>, b<3> >::bs.bl<int,
b<1>, b<3> >::h)) != 0)’ is not a constant expression
    5 |   constexpr d(const int *e, int) : f{e}, ae{} { f ? (void)0 :
assertFail(); }
      | 

The code compiles fine without -fsanitize=undefined. Clang compiles just fine
with or without sanitizer, see results on Godbolt:
https://godbolt.org/z/6WKqsGY6x

Essentially the code at line 5 is asserting that the input pointer "e" is not
nullptr. The rest of the code does not instantiate the class with a nullptr,
thus the assert is not triggered and the code can be constexpr. But somehow
ubsan breaks that. Clang's ubsan doesn't.

So I wanted to check with you if you believe this is a bug in GCC's ubsan or if
this case is simply not expected to be supported.

Thank you!
  • [Bug sanitizer/121731] New: &q... carlosgalvezp at gmail dot com via Gcc-bugs

Reply via email to