Re: Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread marco . bodrato
Ciao, 3 set 2023, 22:16 da ni...@lysator.liu.se: > Andrew Teylu writes: > > I see no good reason to involve any signed values here, though. Maybe > the variable neg, and the return value, should be changed to mp_limb_t, > or at least unsigned int? > Yes, unsigned is the best choice, it used

Re: Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread Vincent Lefevre
On 2023-09-03 22:16:21 +0200, Niels Möller wrote: > Andrew Teylu writes: > > >> I am not sure the arithmetic on unsigned types is what clang is unhappy > >> about, though. Perhaps it dislikes the xor with "neg", which is a > >> signed variable. > > I can't say precisely what implicit

Re: Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread Andrew Teylu
On Sun, Sep 3, 2023 at 9:16 PM Niels Möller wrote: > Does it make any difference if you change the "1" constants to "1u" ? > I'll try this in the morning and see if the runtime error goes away or not. > I see no good reason to involve any signed values here, though. Maybe > the variable neg,

Re: Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread Niels Möller
Andrew Teylu writes: >> I am not sure the arithmetic on unsigned types is what clang is unhappy >> about, though. Perhaps it dislikes the xor with "neg", which is a >> signed variable. I can't say precisely what implicit conversions happen according to the spec: Unsigned to signed is always

Re: Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread Andrew Teylu
On Sun, Sep 3, 2023 at 7:16 PM Torbjörn Granlund wrote: > > Andrew Teylu writes: > > When I run `multiply.c` from gmpbench [https://gmplib.org/gmpbench], > I'm seeing an unsigned integer overflow in `toom_eval_pm2.c` on this > line: > > neg ^= ((k & 1) - 1) > > I fully appreciate that

Re: Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread Torbjörn Granlund
Andrew Teylu writes: When I run `multiply.c` from gmpbench [https://gmplib.org/gmpbench], I'm seeing an unsigned integer overflow in `toom_eval_pm2.c` on this line: neg ^= ((k & 1) - 1) I fully appreciate that unsigned integer overflow is implementation defined, but I am not sure

Unsigned integer overflow in `toom_eval_pm2.c`

2023-09-03 Thread Andrew Teylu
Hi, I'm working with gmp-6.3.0 compiled with clang 16 and its `-fsanitize=integer` flag. When I run `multiply.c` from gmpbench [https://gmplib.org/gmpbench], I'm seeing an unsigned integer overflow in `toom_eval_pm2.c` on this line: ``` neg ^= ((k & 1) - 1) ``` The values we're normally