abseil/abseil-cpp

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

Opened this issue · 5 comments

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 4c7e7c7.

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?

7bd9ff9

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

Same issue here.

@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.

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

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

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