[Bug libstdc++/89979] New: subtract_with_carry_engine incorrect carry flag
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89979 Bug ID: 89979 Summary: subtract_with_carry_engine incorrect carry flag Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: g...@christoph-conrads.name Target Milestone: --- Created attachment 46090 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46090&action=edit The initial state in combination with the incorrect carry computation makes the PRNG enter the unescapable all zero state. The carry inside `std::subtract_with_carry_engine` is computed incorrectly if word_size == std::numeric_limits::digits. The bug can be triggered neither by std::ranlux24 nor by std::ranlux48. The bug occurs with GCC 7.3.0, GCC 8.2.0, and Clang when using the GNU Standard C++ Library shipping with GCC 7.3.0. $ gcc --version gcc (Gentoo 7.3.0-r3 p1.4) 7.3.0 Copyright (C) 2017 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++-7.3.0 -Wextra -Wall -std=c++11 -pedantic -v -save-temps ~/libstdcxx-swc-bug.cpp Using built-in specs. COLLECT_GCC=g++-7.3.0 COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/7.3.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 7.3.0-r3 p1.4' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --with-multilib-list=m64 --disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --disable-libmpx --enable-vtable-verify --enable-libvtv --enable-lto --without-isl --enable-libsanitizer --enable-default-pie --enable-default-ssp Thread model: posix gcc version 7.3.0 (Gentoo 7.3.0-r3 p1.4) COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-std=c++11' '-Wpedantic' '-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/cc1plus -E -quiet -v -D_GNU_SOURCE /home/starfish/libstdcxx-swc-bug.cpp -mtune=generic -march=x86-64 -std=c++11 -Wextra -Wall -Wpedantic -fpch-preprocess -o libstdcxx-swc-bug.ii ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7 /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/x86_64-pc-linux-gnu /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7/backward /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-std=c++11' '-Wpedantic' '-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/cc1plus -fpreprocessed libstdcxx-swc-bug.ii -quiet -dumpbase libstdcxx-swc-bug.cpp -mtune=generic -march=x86-64 -auxbase libstdcxx-swc-bug -Wextra -Wall -Wpedantic -std=c++11 -version -o libstdcxx-swc-bug.s GNU C++11 (Gentoo 7.3.0-r3 p1.4) version 7.3.0 (x86_64-pc-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++11 (Gentoo 7.3.0-r3 p1.4) version 7.3.0 (x86_64-pc-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 3.1.6, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 09ac773f85349e020b5b36ead38f9924 COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-std=c++11' '
[Bug libstdc++/89979] subtract_with_carry_engine incorrect carry flag
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89979 --- Comment #1 from Christoph Conrads --- There is no attachment with the preprocessed code demonstrating the problem because the this code is 1.2 MB large.
[Bug libstdc++/80977] uniform_int_distribution downscaling throws away perfectly good entropy
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80977 Christoph Conrads changed: What|Removed |Added CC||g...@christoph-conrads.name --- Comment #1 from Christoph Conrads --- Created attachment 44801 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44801&action=edit C++11 code demonstrating GCC bug 80977 This file contains * code demonstrating GCC bug 80977 and * a modified version of std::uniform_int_distribution without bug 80977 when operator() is invoked. The modified implementation can be used by replacing `std::uniform_int_distribution` with `standard:uniform_int_distribution` in main(). The code triggers two warnings in lines 178 and 208 with `-Woverflow`. Line 178 belongs to modified code and overflow there is handled in lines 180-184. The warning in line 208 is caused by unmodified libstdc++ code but judging by the comment "wraparound control" in line 205, this is handled properly.
[Bug libstdc++/80977] uniform_int_distribution downscaling throws away perfectly good entropy
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80977 --- Comment #2 from Christoph Conrads --- Created attachment 44802 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44802&action=edit Patch proposal for GCC bug 80977 This patch attempts to fix bug 80977. The code in __generate_impl was not tested but the issue is the same. Curiously, __generate_impl handles the case correctly where the right interval boundaries of generator and uniform_int_distribution are powers of two while operator() does not. The patch was created based on commit 16db from October 7, 2017.
[Bug libstdc++/80977] uniform_int_distribution downscaling throws away perfectly good entropy
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80977 --- Comment #3 from Christoph Conrads --- With GCC bug 80977, half of all values from the random bit generator may be ignored by std::uniform_int_distribution.
[Bug c++/88173] New: `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 Bug ID: 88173 Summary: `std::numeric_limits::quiet_NaN()` is not constexpr Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: g...@christoph-conrads.name Target Milestone: --- Consider the following C++11 code: $ cat nan.cpp #include constexpr bool foo(double x) { return !(x <= 0); } int main() { static_assert(std::numeric_limits::has_quiet_NaN, ""); static_assert(!(0 <= std::numeric_limits::quiet_NaN()), ""); static_assert(foo(std::numeric_limits::quiet_NaN()), ""); } I expect this code to compile because `foo()` is a constexpr function and because `std::numeric_limits::quiet_NaN()` must be a constexpr function according to §18.3.2.4 of the C++ standard draft N3337 (and because there are quiet NaNs on my computer). Nevertheless, the code fails to compile with GCC: $ g++ -Wextra -Wall -std=c++11 -pedantic nan.cpp nan.cpp: In function ‘int main()’: nan.cpp:12:2: error: non-constant condition for static assertion static_assert(foo(std::numeric_limits::quiet_NaN()), ""); ^ nan.cpp:12:19: in constexpr expansion of ‘foo(std::numeric_limits::quiet_NaN())’ nan.cpp:5:13: error: ‘(+QNaN <= 0.0)’ is not a constant expression return !(x <= 0); ~~~^ The errors is the same with GCC 7.3.0 on Ubuntu 18.04 LTS (Bionic Beaver), GCC 7.3.0 on Gentoo (no output posted), and GCC 6.3.0 on Raspbian (output below). $ lsb_release --all No LSB modules are available. Distributor ID: Ubuntu Description:Ubuntu 18.04.1 LTS Release:18.04 Codename: bionic $ g++ -Wextra -Wall -std=c++11 -pedantic -v nan.cpp Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04) COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-std=c++11' '-Wpedantic' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-linux-gnu/7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE nan.cpp -quiet -dumpbase nan.cpp -mtune=generic -march=x86-64 -auxbase nan -Wextra -Wall -Wpedantic -std=c++11 -version -fstack-protector-strong -Wformat-security -o /tmp/ccSEEcsH.s GNU C++11 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/7" ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/7 /usr/include/x86_64-linux-gnu/c++/7 /usr/include/c++/7/backward /usr/lib/gcc/x86_64-linux-gnu/7/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C++11 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 1bfae38ae5df64de6196cbd8c3b07d86 nan.cpp: In function ‘int main()’: nan.cpp:12:2: error: non-consta
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #1 from Christoph Conrads --- Created attachment 45075 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45075&action=edit Code pre-processed with GCC 7.3.0 on Ubuntu 18.04 LTS This file was created with $ g++ -Wextra -Wall -std=c++11 -pedantic --save-temps nan.cpp on Ubuntu 18.04 LTS.
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #2 from Christoph Conrads --- Created attachment 45076 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45076&action=edit Code pre-processed with GCC 6.3.0 on Raspbian 9.4 The file was created with $ g++ -Wextra -Wall -std=c++11 -pedantic --save-temps nan.cpp on Raspbian 9.4 (codename stretch).
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #5 from Christoph Conrads --- Having read the comments, I began to modify code in the bug report. Apparently, the bug is only triggered if QNaN is on the wrong side of the comparison operator: christoph:~$ cat nan-lhs.cpp #include constexpr bool rhs(double f) { return !(0 <= f); } constexpr bool lhs(double f) { return !(f <= 0); } int main() { static_assert(std::numeric_limits::has_quiet_NaN, ""); static_assert(!(std::numeric_limits::quiet_NaN() <= 0), ""); static_assert(!(0 <= std::numeric_limits::quiet_NaN()), ""); static_assert(lhs(std::numeric_limits::quiet_NaN()), ""); static_assert(rhs(std::numeric_limits::quiet_NaN()), ""); } christoph:~$ g++ -Wextra -Wall -std=c++11 -pedantic nan-lhs.cpp nan-lhs.cpp: In function ‘int main()’: nan-lhs.cpp:16:2: error: non-constant condition for static assertion static_assert(!(std::numeric_limits::quiet_NaN() <= 0), ""); ^ nan-lhs.cpp:16:59: error: ‘(+QNaN <= 0.0)’ is not a constant expression static_assert(!(std::numeric_limits::quiet_NaN() <= 0), ""); ~~^ nan-lhs.cpp:18:2: error: non-constant condition for static assertion static_assert(lhs(std::numeric_limits::quiet_NaN()), ""); ^ nan-lhs.cpp:18:19: in constexpr expansion of ‘lhs(std::numeric_limits::quiet_NaN())’ nan-lhs.cpp:10:13: error: ‘(+QNaN <= 0.0)’ is not a constant expression return !(f <= 0); ~~~^ nan-lhs.cpp:19:2: error: non-constant condition for static assertion static_assert(rhs(std::numeric_limits::quiet_NaN()), ""); ^ nan-lhs.cpp:19:19: in constexpr expansion of ‘rhs(std::numeric_limits::quiet_NaN())’ nan-lhs.cpp:5:13: error: ‘(+QNaN >= 0.0)’ is not a constant expression return !(0 <= f); ~~~^ Note that QNaN only appears on the left-hand side in the error messages, irrespective of the user input. christoph:~$ lsb_release --all No LSB modules are available. Distributor ID: Ubuntu Description:Ubuntu 18.04.1 LTS Release:18.04 Codename: bionic christoph:~$ g++ -Wextra -Wall -std=c++11 -pedantic -v nan-lhs.cpp Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04) COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-std=c++11' '-Wpedantic' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-linux-gnu/7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE nan-lhs.cpp -quiet -dumpbase nan-lhs.cpp -mtune=generic -march=x86-64 -auxbase nan-lhs -Wextra -Wall -Wpedantic -std=c++11 -version -fstack-protector-strong -Wformat-security -o /tmp/ccOYNOxa.s GNU C++11 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/7" ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/7 /usr/include/x86_64-linux-gnu/c++/7 /usr/include/c++/7/backward /usr/lib/gcc/x86_64-linux-gnu/7/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C++11 (Ubuntu 7.3.0-27ubuntu1~18.04) version 7.3.0 (x86_64-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP GGC heuristics
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #6 from Christoph Conrads --- Created attachment 45080 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45080&action=edit nan-lhs.ii created by GCC 7.3.0 on Ubuntu 18.04 LTS
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #7 from Christoph Conrads --- Created attachment 45081 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45081&action=edit nan-lhs.ii created by GCC 6.3.0 on Raspbian 9.4
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #8 from Christoph Conrads --- Created attachment 45082 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45082&action=edit nan-lhs.cpp
[Bug c++/88173] `std::numeric_limits::quiet_NaN()` is not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88173 --- Comment #9 from Christoph Conrads --- nan-lhs.cpp with `float` instead of `double` triggers the same error messages with `QNaNf` in place of `QNaN`.