abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
14.88k stars 2.6k forks source link

[Bug]: Constexpr expansion compilation error with GCC's UndefinedBehaviorSanitizer #1634

Open kaxub opened 7 months ago

kaxub commented 7 months ago

Describe the issue

When building abseil with GCC with -fsanitize=undefined, the following compilation error occurs:

/abseil/absl/container/internal/raw_hash_set.h:3364:56:   in 'constexpr' expansion of 'absl::container_internal::hash_policy_traits<absl::container_internal::FlatHashMapPolicy<std::basic_string_view<char>, absl::CommandLineFlag*>, void>::get_hash_slot_fn<absl::container_internal::StringHash>()'
/abseil/absl/container/internal/hash_policy_traits.h:163:54: error: '(absl::container_internal::TypeErasedApplyToSlotFn<absl::container_internal::StringHash, std::basic_string_view<char> > == 0)' is not a constant expression
  163 |     return Policy::template get_hash_slot_fn<Hash>() == nullptr
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
make-4.3[4]: *** [absl/flags/CMakeFiles/flags_reflection.dir/build.make:66: absl/flags/CMakeFiles/flags_reflection.dir/reflection.cc.o] Error 1   

This code producing the error has been introduced with commit 4c7e7c7d9.

The error does not occur when building with no sanitizer or when building with -fsanitize=address or -fsanitize=thread.

This seems to be a known GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962

Steps to reproduce the problem

git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
mkdir build
cd build
cmake -DCMAKE_CXX_FLAGS="-fsanitize=undefined" ..
make

Isolated expression from the method where the error occurs (absl::container_internal::hash_policy_traits::get_hash_slot_fn<Hash>()) with -std=gnu++17 -fsanitize=undefined: https://godbolt.org/z/8bEazf6e5

What version of Abseil are you using?

7bd9ff910d489658da58251de1317eb3f790a2c6

What operating system and version are you using?

Ubuntu 20.04.6 LTS

What compiler and version are you using?

GCC 9.4.0 Also tested with GCC 13.2 on linked godbolt.

What build system are you using?

cmake 3.16.3

Additional context

No response

jnooree commented 7 months ago

Same issue here.

ptrmtrx commented 7 months ago

@derekmauro can somebody from abseil look at it please, it blocks our development. We use google quiche that uses abseil, but we build it by gcc with undefined behavior sanitizer and it results into this bug.

jnooree commented 7 months ago

For a temporary workaround, I used clang for sanitizer builds.

ptrmtrx commented 7 months ago

Unfortunately, t's not an option in our environment.

derekmauro commented 7 months ago

Sorry, this issue is not a priority for me at the moment.

BotellaA commented 3 months ago

Is there any update on this? Is it an abseil issue or a GCC issue?

jnooree commented 3 months ago

This seems to be a known GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962

min-tian-thomas commented 2 weeks ago

A bug of gcc yet abseil may need some workaround to avoid considering it is such a fundamental library

BotellaA commented 2 weeks ago

I had to disable sanitizer checks, which is a bad idea, but I'm not sure what else we can do...