Re: Report: gmp-6.1.2 on MacOS 10.15 using GCC and two Clang
> On 20 Oct 2019, at 21:44, Torbjörn Granlund wrote: > > Hans Åberg writes: > > A common programming error is assuming that signed integer types are > two’s complement, because even though all current CPUs are that, > overflows are undefined in C/C++, and an optimizer can take advantage > of that. One example from [1]: checking overflows with x > x + 1 may > work as intended with optimization turned off, but when on, the > optimizer can assume that it is always false since x + 1 is undefined > when overflowed. > > I believe we assume signed integers are in two's complement. > > We don't do a lot of arithmetic on signed integers, though. Strictly, it is for signed overflows one cannot assume modulo 2^n, n = number of bits. For the unsigned integer types it is required, though. Here is a list for various languages: https://en.wikipedia.org/wiki/Integer_overflow ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: Report: gmp-6.1.2 on MacOS 10.15 using GCC and two Clang
Hans Åberg writes: Strictly, it is for signed overflows one cannot assume modulo 2^n, n = number of bits. For the unsigned integer types it is required, though. Believe it or not, but the GMP devs are pretty good at computer arithmetic. -- Torbjörn Please encrypt, key id 0xC8601622 ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: Report: gmp-6.1.2 on MacOS 10.15 using GCC and two Clang
Hans Åberg writes: A common programming error is assuming that signed integer types are two’s complement, because even though all current CPUs are that, overflows are undefined in C/C++, and an optimizer can take advantage of that. One example from [1]: checking overflows with x > x + 1 may work as intended with optimization turned off, but when on, the optimizer can assume that it is always false since x + 1 is undefined when overflowed. I believe we assume signed integers are in two's complement. We don't do a lot of arithmetic on signed integers, though. -- Torbjörn Please encrypt, key id 0xC8601622 ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: Report: gmp-6.1.2 on MacOS 10.15 using GCC and two Clang
> On 20 Oct 2019, at 13:24, Torbjörn Granlund wrote: > > Hans Åberg writes: > > I have compiled gmp-6.1.2 on MacOS 10.15 using the inhouse Apple clang > and the MacPorts gcc9 and clang9, with ‘make check’. All tests passed > on gcc9, but the two clang had one error each. > > Several people seem to have trouble with using clang. When clang first > appeared, I isolated several of the GMP failures only to determine that > they were clang codegen bugs. I don't have time to debug clang for > Apple or the other clang devs, and this new GMP failure is with very > high probability yet another clang codegen bug. Then I will have to do it for you: :-) It is an optimization issue. When turning it off, both clang pass. A common programming error is assuming that signed integer types are two’s complement, because even though all current CPUs are that, overflows are undefined in C/C++, and an optimizer can take advantage of that. One example from [1]: checking overflows with x > x + 1 may work as intended with optimization turned off, but when on, the optimizer can assume that it is always false since x + 1 is undefined when overflowed. I do not know if anything like that is done in GMP. 1. http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: Report: gmp-6.1.2 on MacOS 10.15 using GCC and two Clang
Hans Åberg writes: I have compiled gmp-6.1.2 on MacOS 10.15 using the inhouse Apple clang and the MacPorts gcc9 and clang9, with ‘make check’. All tests passed on gcc9, but the two clang had one error each. Several people seem to have trouble with using clang. When clang first appeared, I isolated several of the GMP failures only to determine that they were clang codegen bugs. I don't have time to debug clang for Apple or the other clang devs, and this new GMP failure is with very high probability yet another clang codegen bug. -- Torbjörn Please encrypt, key id 0xC8601622 ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Report: gmp-6.1.2 on MacOS 10.15 using GCC and two Clang
I have compiled gmp-6.1.2 on MacOS 10.15 using the inhouse Apple clang and the MacPorts gcc9 and clang9, with ‘make check’. All tests passed on gcc9, but the two clang had one error each. % uname -a Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64 —— % /opt/local/bin/gcc-mp-9 --version gcc-mp-9 (MacPorts gcc9 9.2.0_1) 9.2.0 Compiler warnings: ../../gmp-6.1.2/printf/obprintf.c:59: warning: ISO C forbids an empty translation unit [-Wpedantic] 59 | #endif /* HAVE_OBSTACK_VPRINTF */ ../../gmp-6.1.2/printf/obvprintf.c:52: warning: ISO C forbids an empty translation unit [-Wpedantic] 52 | #endif /* HAVE_OBSTACK_VPRINTF */ ../../gmp-6.1.2/printf/obprntffuns.c:72: warning: ISO C forbids an empty translation unit [-Wpedantic] 72 | #endif /* HAVE_OBSTACK_VPRINTF */ % make check passed without errors —— % /usr/bin/clang --version Apple clang version 11.0.0 (clang-1100.0.33.8) Target: x86_64-apple-darwin19.0.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin Compiler warnings: libtool: compile: /usr/bin/clang -DHAVE_CONFIG_H -I. -I../../gmp-6.1.2/mpn -I.. -D__GMP_WITHIN_GMP -I../../gmp-6.1.2 -DOPERATION_toom_interpolate_5pts -O2 -pedantic -fomit-frame-pointer -m64 -mtune=skylake -march=broadwell -c toom_interpolate_5pts.c -fno-common -DPIC -o .libs/toom_interpolate_5pts.o toom_interpolate_5pts.c:71:19: warning: expression result unused [-Wunused-value] ASSERT_NOCARRY (mpn_divexact_by3 (v2, v2, kk1));/* v2 <- v2 / 3 */ ^~~ ../../gmp-6.1.2/gmp-impl.h:1621:6: note: expanded from macro 'mpn_divexact_by3' (3 & mpn_bdiv_dbm1 (dst, src, size, __GMP_CAST (mp_limb_t, GMP_NUMB_MASK / 3))) ~ ^ ../../gmp-6.1.2/gmp-impl.h:2412:33: note: expanded from macro 'ASSERT_NOCARRY' #define ASSERT_NOCARRY(expr) (expr) ^~~~ 1 warning generated. toom_interpolate_8pts.c:164:18: warning: expression result unused [-Wunused-value] ASSERT_NOCARRY(mpn_divexact_by3 (r5, r5, 3 * n + 1)); ~~~^ ../../gmp-6.1.2/gmp-impl.h:1621:6: note: expanded from macro 'mpn_divexact_by3' (3 & mpn_bdiv_dbm1 (dst, src, size, __GMP_CAST (mp_limb_t, GMP_NUMB_MASK / 3))) ~ ^ ../../gmp-6.1.2/gmp-impl.h:2412:33: note: expanded from macro 'ASSERT_NOCARRY' #define ASSERT_NOCARRY(expr) (expr) ^~~~ ../../gmp-6.1.2/printf/obprintf.c:59:34: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit] #endif /* HAVE_OBSTACK_VPRINTF */ ^ ../../gmp-6.1.2/printf/obvprintf.c:52:34: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit] #endif /* HAVE_OBSTACK_VPRINTF */ ^ ../../gmp-6.1.2/printf/repl-vsnprintf.c:396:30: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit] #endif /* ! HAVE_VSNPRINTF */ ^ % make check errors ../../../gmp-6.1.2/test-driver: line 107: 30266 Segmentation fault: 11 "$@" > $log_file 2>&1 FAIL: t-toom53 —— % /opt/local/bin/clang-mp-9.0 --version clang version 9.0.0 (tags/RELEASE_900/final) Target: x86_64-apple-darwin19.0.0 Thread model: posix InstalledDir: /opt/local/libexec/llvm-9.0/bin Compiler warnings: toom_interpolate_5pts.c:71:19: warning: expression result unused [-Wunused-value] ASSERT_NOCARRY (mpn_divexact_by3 (v2, v2, kk1));/* v2 <- v2 / 3 */ ^~~ ../../gmp-6.1.2/gmp-impl.h:1621:6: note: expanded from macro 'mpn_divexact_by3' (3 & mpn_bdiv_dbm1 (dst, src, size, __GMP_CAST (mp_limb_t, GMP_NUMB_MASK / 3))) ~ ^ ../../gmp-6.1.2/gmp-impl.h:2412:33: note: expanded from macro 'ASSERT_NOCARRY' #define ASSERT_NOCARRY(expr) (expr) ^~~~ toom_interpolate_8pts.c:164:18: warning: expression result unused [-Wunused-value] ASSERT_NOCARRY(mpn_divexact_by3 (r5, r5, 3 * n + 1)); ~~~^ ../../gmp-6.1.2/gmp-impl.h:1621:6: note: expanded from macro 'mpn_divexact_by3' (3 & mpn_bdiv_dbm1 (dst, src, size, __GMP_CAST (mp_limb_t, GMP_NUMB_MASK / 3))) ~ ^ ../../gmp-6.1.2/gmp-impl.h:2412:33: note: expanded from macro 'ASSERT_NOCARRY' #define ASSERT_NOCARRY(expr) (expr) ^~~~ ../../gmp-6.1.2/printf/obprintf.c:59:34: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit] #endif /* HAVE_OBSTACK_VPRINTF */ ^ ../../gmp-6.1.2/printf/obvprintf.c:52:34: warning: ISO C requires a translation unit to contain at least one declaration [-Wempty-translation-unit] #endif /* HAVE_OBSTACK_VPRINTF */