[PATCH] D142279: [cmake] Use LLVM_ENABLE_ASSERTIONS to enable assertions in libstdc++
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 9 00:18:20 PST 2023
foad added a comment.
In D142279#4113901 <https://reviews.llvm.org/D142279#4113901>, @srj wrote:
> This change introduces compilation errors when building in at least some version(s) of gcc/g++; while what we're seeing is clearly a gcc/g++ bug, it would be good to avoid it if possible.
>
> With gcc at version Debian 12.2.0-10:
>
> echo '#include <string>
> void f(int n) {
> for (int i = 0; i < n; i++) {
> std::string s;
> switch (i) {
> case 0: s = "x"; break;
> case 1: s = "y"; break;
> case 2: s = "z"; break;
> case 3: s = "w"; break;
> default: s = std::to_string(i); break;
> }
> }
> }
> ' | g++ -D_GLIBCXX_ASSERTIONS -x c++ - -O3 -Werror=restrict -c -o /dev/null
>
> This will result in the compilation failure:
>
> In file included from /usr/include/c++/12/string:40,
> from <stdin>:1:
> In static member function ‘static std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
> inlined from ‘static 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/include/c++/12/bits/basic_string.h:423:21,
> inlined from ‘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/include/c++/12/bits/basic_string.tcc:532:22,
> inlined from ‘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/include/c++/12/bits/basic_string.h:1647:19,
> inlined from ‘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/include/c++/12/bits/basic_string.h:815:28,
> inlined from ‘void f(int)’ at <stdin>:6:17:
> /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [18, 9223372036854775807] and 17 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
> 431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
> | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
>
> ...again, while this seems almost certainly to be a bug in defining _GLIBCXX_ASSERTIONS for (some?) versions of gcc, it means you can't compile LLVM from source using this version of gcc with this patch in place.
>
> If it possible to finesse this patch to detect the gcc version and avoid defining _GLIBCXX_ASSERTIONS? Alternately, could there be a way to continue allowing LLVM_ENABLE_ASSERTIONS to be set, without defining _GLIBCXX_ASSERTIONS?
I can reproduce the error above on a debian:bookworm docker using gcc-12 12.2.0-14. But why are you hitting this when building LLVM? Where does -Werror=restrict come from? I don't think we enable that in normal LLVM builds.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142279/new/
https://reviews.llvm.org/D142279
More information about the llvm-commits
mailing list