Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] build fails with libstdc++ 12.1.0 #1398

Closed
jdoubleu opened this issue May 19, 2022 · 6 comments
Closed

[BUG] build fails with libstdc++ 12.1.0 #1398

jdoubleu opened this issue May 19, 2022 · 6 comments

Comments

@jdoubleu
Copy link

jdoubleu commented May 19, 2022

Describe the bug
When I compile the Google benchmark library with g++ 12.1 (using libstdc++ 12.1) in C++20 mode, I get the following error:

In file included from /usr/local/include/c++/12.1.0/string:40,
                 from /__w/googletest-issue/googletest-issue/build/_deps/google-benchmark-src/include/benchmark/benchmark.h:186,
                 from /__w/googletest-issue/googletest-issue/build/_deps/google-benchmark-src/src/benchmark.cc:15:
In static member function 'static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)',
    inlined from 'static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/local/include/c++/12.1.0/bits/basic_string.h:423:21,
    inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/local/include/c++/12.1.0/bits/basic_string.tcc:532:22,
    inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::assign(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/local/include/c++/12.1.0/bits/basic_string.h:1647:19,
    inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /usr/local/include/c++/12.1.0/bits/basic_string.h:815:28,
    inlined from 'size_t benchmark::RunSpecifiedBenchmarks(BenchmarkReporter*, BenchmarkReporter*, std::string)' at /__w/googletest-issue/googletest-issue/build/_deps/google-benchmark-src/src/benchmark.cc:459:12:
/usr/local/include/c++/12.1.0/bits/char_traits.h:431:56: error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
  431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));

System
Which OS, compiler, and compiler version are you using:

  • OS: linux
  • Compiler and version: gcc 12.1.0

To reproduce
I've prepared a repository to reproduce the issue: https://github.com/jdoubleu/googlebenchmark-issue-1398
You can checkout the build output from the CI here: https://github.com/jdoubleu/googlebenchmark-issue-1398/runs/6505920315?check_suite_focus=true

Steps to reproduce the behavior:

  1. checkout the latest version
  2. build (and link) the library
  3. See error

Expected behavior
The library compiles with the latest gcc version (including libstdc++).

Additional context
Interestingly, I get a similar error when compiling googletest. However, the build doesn't fail (see).

The error looks like some sort of an underflow in __builtin_memcpy(void*, const void*, long unsigned int) (notice the "accessing 9223372036854775810 or more bytes"). Since it is called from std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type), it may have something to do with Unicode used with std::string?

@LebedevRI
Copy link
Collaborator

I'm 99% sure it's an GCC/libstdc++ bug. Could you reduce the reproducer further, down to a single 10-line function?

@jdoubleu
Copy link
Author

jdoubleu commented May 19, 2022

I'm 99% sure it's an GCC/libstdc++ bug.

Yes, something like this. clang 14 with libc++ and VS 2022 look fine.

I've added two scripts to the repo, which build the project and the library itself inside a Docker container. You can run those on a linux host, if you've Docker installed.

When building google-benchmark with bazel, I do not get an error. I'm not sure if bazel actually uses g++ 12.1 or if the tests actually use the TEST macro, which seems to produce these errors.

@H-G-Hristov
Copy link

Looks like it builds on Ubuntu 22.04 with the provided 12.0.

@jdoubleu
Copy link
Author

jdoubleu commented Jun 8, 2022

Which "provided" g++ do you mean?
On Ubuntu 22.04 I can only install gcc 11.2.0 through apt at the moment.

The CI still fails with g++ 12.1.0 (and the latest Ubuntu): https://github.com/jdoubleu/googlebenchmark-issue-1398/runs/6794168005?check_suite_focus=true

@H-G-Hristov
Copy link

H-G-Hristov commented Jun 8, 2022

There is 12.0 package in Ubuntu 22.04 that's probably the prerelease one.
https://packages.ubuntu.com/jammy/devel/

@jdoubleu
Copy link
Author

jdoubleu commented Aug 3, 2022

You were right! It's a bug in gcc 12+. See the following tickets:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants