[Bug c++/80265] __builtin_{memcmp,memchr,strlen} are not usable in constexpr functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80265 janisozaur+gcc at gmail dot com changed: What|Removed |Added CC||janisozaur+gcc at gmail dot com --- Comment #37 from janisozaur+gcc at gmail dot com --- Hi, I ran into what I think is a variant of this bug. Here's the problem presented with godbolt: https://godbolt.org/z/SP-4uG And the contents of that link, as reproduced on my machine, are: #include #include static const std::wstring_view foo = L"foo"; static constexpr std::wstring_view bar = L"bar"; $ g++ --version g++ (GCC) 8.2.1 20181127 $ g++ -c test.cpp -Wall -Wextra -std=c++17 # exit code 0 $ gcc9/bin/g++ --version g++ (GCC) 9.0.1 20190225 (experimental) $ gcc9/bin/g++ -c test.cpp -Wall -Wextra -std=c++17 # exit code 0 $ clang++ --version clang version 7.0.1 (tags/RELEASE_701/final) $ clang++ -c -Wall -Wextra test.cpp -std=c++17 -Wno-unused-const-variable -stdlib=libc++ # exit code 0 $ clang++ -c -Wall -Wextra test.cpp -std=c++17 test.cpp:4:36: error: constexpr variable 'bar' must be initialized by a constant expression static constexpr std::wstring_view bar = L"bar"; ^ ~~ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../include/c++/8.2.1/bits/char_traits.h:431:11: note: non-constexpr function 'wcslen' cannot be used in a constant expression return wcslen(__s); ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../include/c++/8.2.1/string_view:100:39: note: in call to 'length(&L"bar"[0])' : _M_len{__str == nullptr ? 0 : traits_type::length(__str)}, ^ test.cpp:4:42: note: in call to 'basic_string_view(&L"bar"[0])' static constexpr std::wstring_view bar = L"bar"; ^ 1 error generated. Relevant piece of code from libstdc++: https://github.com/gcc-mirror/gcc/blob/9fb89fa845c1b2e0a18d85ada0b077c84508ab78/libstdc%2B%2B-v3/include/bits/char_traits.h#L426-L431 Unfortunately, I can't really test clang with libstdc++ trunk. Please let me know if it is sufficient to leave this comment here or should I open another ticket?
[Bug c++/84357] New: Incorrect 'foo' is used uninitialized with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84357 Bug ID: 84357 Summary: Incorrect 'foo' is used uninitialized with -O3 Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: janisozaur+gcc at gmail dot com Target Milestone: --- Created attachment 43402 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43402&action=edit reproducer Compile attachment with `-O3 -Werror -Wuninitialized`, tested with GCC 8.0.1 20180211 on wandbox: https://wandbox.org/permlink/jW0p9vIwIwHOEmEb prog.c: In function 'foo': prog.c:24:14: error: 'i' is used uninitialized in this function [-Werror=uninitialized] for (int i = 0; i < COUNT; i++) ^ cc1: all warnings being treated as errors
[Bug c/68044] New: ceil() with -O3 and -masm=intel fails to compile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68044 Bug ID: 68044 Summary: ceil() with -O3 and -masm=intel fails to compile Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: janisozaur+gcc at gmail dot com Target Milestone: --- Created attachment 36559 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36559&action=edit test case file on Arch Linux with gcc 5.2.0, glibc 2.22-3 Test case to be compiled with: gcc test.c -o test -m32 -O3 -masm=intel the ceil() function is taken from /usr/include/bits/mathinline.h, verbatim provided here: __inline_mathcodeNP (ceil, __x, \ register long double __value; \ register int __ignore; \ unsigned short int __cw;\ unsigned short int __cwtmp; \ __asm __volatile ("fnstcw %3\n\t" \ "movzwl %3, %1\n\t" \ "andl $0xf3ff, %1\n\t"\ "orl $0x0800, %1\n\t" /* rounding up */ \ "movw %w1, %2\n\t"\ "fldcw %2\n\t"\ "frndint\n\t" \ "fldcw %3"\ : "=t" (__value), "=&q" (__ignore), "=m" (__cwtmp), \ "=m" (__cw) \ : "0" (__x)); \ return __value) This works fine without -masm=intel
[Bug tree-optimization/105937] [12 Regression] maybe-uninitialized with std::optional
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105937 --- Comment #7 from janisozaur+gcc at gmail dot com --- Will the fix get merged to 12.3 as well? This currently prevents the project I work on from compiling with GCC (https://github.com/OpenRCT2/OpenRCT2/issues/17371)
[Bug c++/105937] New: [12] Regression with maybe-uninitialized
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105937 Bug ID: 105937 Summary: [12] Regression with maybe-uninitialized Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: janisozaur+gcc at gmail dot com Target Milestone: --- Created attachment 53125 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53125&action=edit Test case extracted from original code Commit https://gcc.gnu.org/g:6feb628a706e86eb3f303aff388c74bdb29e7381 "Improve warning suppression for inlined functions [PR98512]. " introduced a regression when using std::optional. Ever since that commit, when building optimized code compiler complains: /home/mijn/workspace/openrct2/src/openrct2/drawing/Drawing.String.cpp: In function ‘void ttf_process_string_literal(OpenRCT2::IContext*, std::string_view)’: /home/mijn/workspace/openrct2/src/openrct2/drawing/Drawing.String.cpp:215:62: error: ‘*(long unsigned int*)((char*)&ttfRunIndex + offsetof(std::optional,std::optional::.std::_Optional_base::))’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 215 | auto len = it.GetIndex() - ttfRunIndex.value(); | ^ gcc -v: Using built-in specs. COLLECT_GCC=/home/mijn/workspace/gcc-install-master/bin/c++ COLLECT_LTO_WRAPPER=/home/mijn/workspace/gcc-install-master/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc/configure --prefix=/home/mijn/workspace/gcc-install-master --enable-languages=c++ Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.0.0 20210702 (experimental) (GCC) Provided an extracted test case for the issue mentioned. Original code: https://github.com/OpenRCT2/OpenRCT2/blob/b0ffa9d28e62b862f68a37788931265cb4528835/src/openrct2/drawing/Drawing.String.cpp#L839 Original bug report for OpenRCT2: https://github.com/OpenRCT2/OpenRCT2/issues/17371 Test case on godbolt: https://godbolt.org/z/6Y3cn1Ks1 c++ -O2 -c -o foo test.cpp -Werror=maybe-uninitialized
[Bug c++/114519] New: GCC 14 trunk fails to compile chrono with -fno-char8_t -std=gnu++20
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114519 Bug ID: 114519 Summary: GCC 14 trunk fails to compile chrono with -fno-char8_t -std=gnu++20 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: janisozaur+gcc at gmail dot com Target Milestone: --- Created attachment 57830 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57830&action=edit failure log gcc 20240328 Godbolt link: https://godbolt.org/z/e8GG8znTh test.cpp: #include Compilation: g++ -std=gnu++20 -fno-char8_t Version: /home/mijn/workspace/gcc-install-master/bin/g++ --version g++ (GCC) 14.0.1 20240328 (experimental) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Expected result: compiles without issues. It compiles correctly with GCC 13 Result: Full output in the attachment, only the last line quoted below: /opt/compiler-explorer/gcc-trunk-20240328/include/c++/14.0.1/format:707:58: error: 'consteval bool std::__unicode::__literal_encoding_is_unicode() [with _CharT = char]' called in a constant expression 707 | if constexpr (__literal_encoding_is_unicode<_CharT>()) | ~^~ Compiler returned: 1
[Bug c++/114592] New: Bogus `maybe-uninitialized` on std::variant with std::string with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114592 Bug ID: 114592 Summary: Bogus `maybe-uninitialized` on std::variant with std::string with -O3 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: janisozaur+gcc at gmail dot com Target Milestone: --- Created attachment 57879 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57879&action=edit minimized reproducer When trying to compile source file which creates a std::variant which holds std::string and push it to std::vector, I get bogus warning about string's internals being left uninitialized. This only happens when using -O3, lower optimisations do not exhibit this issue. $ g++ --version g++ (GCC) 14.0.1 20240404 (experimental) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -Werror=maybe-uninitialized -O3 -std=gnu++20 -c test-maybe-uninitialized-gcc14.cpp <...snip...> /path/gcc-install-master/include/c++/14.0.1/bits/basic_string.h:271:17: error: ‘*(const std::__cxx11::basic_string, std::allocator >*)((char*)& + offsetof(std::value_type, std::variant, std::allocator > >::.std::__detail::__variant::_Variant_base, std::allocator > >::.std::__detail::__variant::_Move_assign_base, std::allocator > >::.std::__detail::__variant::_Copy_assign_base, std::allocator > >::.std::__detail::__variant::_Move_ctor_base, std::allocator > >::.std::__detail::__variant::_Copy_ctor_base, std::allocator > >::.std::__detail::__variant::_Variant_storage, std::allocator > >::_M_u)).std::__cxx11::basic_string::_M_string_length’ may be used uninitialized [-Werror=maybe-uninitialized] 271 | if (_M_string_length > _S_local_capacity) | ^~~~ test-maybe-uninitialized-gcc14.cpp: In function ‘void BuildAnyArgListFromLegacyArgBuffer(std::vector, std::allocator > > >&, const void*&)’: test-maybe-uninitialized-gcc14.cpp:20:22: note: ‘’ declared here 20 | anyArgs.push_back(sz); | ~^~~~ It seems to be present in GCC 12 already, last working version is GCC 11 Original code: https://github.com/OpenRCT2/OpenRCT2/blob/318bff1eac9a51b49ce20029d7a552efdd18e1cd/src/openrct2/localisation/Formatting.cpp#L795 godbolt reproducer with minimized test case: https://godbolt.org/z/9GT9PKTxG