Hi Jakub,
The bitint-97.c test starts failing after this commit with all targets running
on arm-none-eabi.
Testing torture/bitint-97.c, -O0
doing compile
Executing on host: /build/r17-6056-g9adb420e4826a6/bin/arm-none-eabi-gcc
/build/gcc_src/gcc/testsuite/gcc.dg/torture/bitint-97.c -mthumb -march=armv7ve+simd
-mcpu=cortex-a7 -mfloat-abi=hard -mfpu=auto -dumpbase ""
-fdiagnostics-plain-output -O0 -std=c2y -pedantic-errors -fwrapv
--specs=rdimon.specs -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs
-Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat -Wl,-wrap,exit -Wl,-wrap,_exit
-Wl,-wrap,main -Wl,-wrap,abort -Wl,gcc_tg.o -lm -T qemu.ld -o ./bitint-97.exe (timeout
= 800)
spawn -ignore SIGHUP /build/r17-6056-g9adb420e4826a6/bin/arm-none-eabi-gcc
/build/gcc_src/gcc/testsuite/gcc.dg/torture/bitint-97.c -mthumb
-march=armv7ve+simd -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=auto -dumpbase
-fdiagnostics-plain-output -O0 -std=c2y -pedantic-errors -fwrapv
--specs=rdimon.specs -Wl,--start-group -lc -lm -Wl,--end-group
--specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat
-Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,gcc_tg.o -lm
-T qemu.ld -o ./bitint-97.exe
pid is 1800122 -1800122
pid is -1
output is status 0
PASS: gcc.dg/torture/bitint-97.c -O0 (test for excess errors)
spawning command qemu-system-arm -nographic -machine virt -cpu cortex-a7 -m
256 -semihosting -monitor /dev/null -kernel ./bitint-97.exe
spawn qemu-system-arm -nographic -machine virt -cpu cortex-a7 -m 256
-semihosting -monitor /dev/null -kernel ./bitint-97.exe
*** EXIT code 4242
*** EXIT code 1
pid is -1
Shell closed.
Output is
*** EXIT code 4242
*** EXIT code 1
FAIL: gcc.dg/torture/bitint-97.c -O0 execution test
Running the test for arm-none-eabi in GDB, it gives me this:
Breakpoint 1, bar (a=0x47ff8fd4 "", b=0x47ff8fcc "\377", c=0x47ff8fc4
"\377\377\377\377\377")
at /build/gcc_src/gcc/testsuite/gcc.dg/torture/bitint-97.c:10
warning: Source file is more recent than executable.
10 a[2] = b[2] / c[2];
(gdb) x/i $pc
=> 0x59a <bar+90>: sdiv r2, r1, r2
(gdb) p $r1
$1 = -1
(gdb) p $r2
$2 = -1
(gdb) si
0x0000059e 10 a[2] = b[2] / c[2];
(gdb) p $r2
$3 = 1
(gdb)
As the value is "1", it's illegal for the type, right?
If I run the same test on x86_64-linux-gnu, it passes, so I'm not really sure
what is going on here.
Any ideas?
Kind regards,
Torbjörn
On 2026-11-02 16:46, Jakub Jelinek wrote:
Hi!
When working on the C++ _BitInt support (just posted), I've noticed that
4 recentish bitint tests are just dg-do compile instead of dg-do run
as I've meant. 3 of those work without any changes, the 4th runs into
some problems. Three of them are problems in the testcase, for
signed _BitInt(1) -1 * -1 and -1 % -1 invoke UB and the check for
return value of large negative bit-precise int times 0, and there is
a question what -- and ++ operators should do on signed _BitInt(1), because
they are defined as E-=1 or E+=1 where 1 is of the appropriate type,
but signed _BitInt(1) doesn't have value 1, so we need E+=-1 and E-=-1
instead.
Given
int
main ()
{
signed _BitInt(3) a;
a = 3wb;
++a;
a = -3wb - 1;
--a;
signed char b;
b = __SCHAR_MAX__;
++b;
b = -__SCHAR_MAX__ - 1;
--b;
}
with -fsanitize=undefined, I think we already implement the
signed _BitInt --/++ as C23/C2Y says so right now, i.e. for
bit-precise integers it uses 1 of the appropriate type, for other
types too, but given E+=1 and E-=1 promotion rules for signed
char/char/signed short or extended signed integer types with precision
smaller than int do promote.
So it is just the weird signed _BitInt(1) case.
For C++ with the patch I've posted it behaves similarly despite the
current wording of the proposal, which I hope will be changed.
Anyway, is this patch ok for trunk?
2026-11-02 Jakub Jelinek <[email protected]>
* gcc.dg/torture/bitint-96.c: Change dg-do compile to dg-do run.
(bar): Avoid signed _BitInt(1) -1 * -1 and -1 % -1 as that is UB.
Don't do predecrement and postincrement for now at runtime.
(main): Fix expected result of -large * 0 multiplication.
* gcc.dg/torture/bitint-97.c: Change dg-do compile to dg-do run.
* gcc.dg/torture/bitint-98.c: Likewise.
* gcc.dg/torture/bitint-99.c: Likewise.
--- a/gcc/testsuite/gcc.dg/torture/bitint-96.c 2026-04-28 08:54:25.379972942
+0200
+++ b/gcc/testsuite/gcc.dg/torture/bitint-96.c 2026-11-02 14:57:32.415742429
+0100
@@ -1,5 +1,5 @@
/* C2Y N3747 - Integer Sets, v5 */
-/* { dg-do compile { target bitint } } */
+/* { dg-do run { target bitint } } */
/* { dg-options "-std=c2y -pedantic-errors" } */
#define expr_has_type(e, t) _Generic (e, default : 0, t : 1)
@@ -39,11 +39,11 @@ bar (_BitInt(1) a[21], signed _BitInt(1)
a[4] = b[4] - c[4];
a[5] = b[5] - c[5];
a[6] = b[6] * c[6];
- a[7] = b[7] * c[8];
+ a[7] = b[7] * c[7];
a[8] = b[8] * c[8];
a[9] = b[9] / c[9];
a[10] = b[10] % c[10];
- a[11] = b[11] % c[11];
+ a[11] = b[10] % c[11];
a[12] = b[12] & c[12];
a[13] = b[13] & c[13];
a[14] = b[14] & c[14];
@@ -87,8 +87,16 @@ main ()
{
if (b != 0 || c != -1)
__builtin_abort ();
- --b;
- ++c;
+ if (0)
+ {
+ --b;
+ ++c;
+ }
+ else
+ {
+ b += (_BitInt(1)) -1wb;
+ c -= (_BitInt(1)) -1wb;
+ }
if (b != -1 || c != 0)
__builtin_abort ();
b = ~b;
@@ -118,7 +126,7 @@ main ()
0, 0, -1,
0, -1, -1,
0, 0, -1
- };
+ };
bar (e, f, g);
_BitInt(1) h[21] = {
0, -1, -1,
@@ -139,8 +147,7 @@ main ()
__builtin_abort ();
if (baz
(24807048826655379640613156875228202584070386120119745959437529938064756141700wb,
0wb) != 0wb)
__builtin_abort ();
- if (baz
(-24807048826655379640613156875228202584070386120119745959437529938064756141700wb,
0wb)
- !=
24807048826655379640613156875228202584070386120119745959437529938064756141700wb)
+ if (baz
(-24807048826655379640613156875228202584070386120119745959437529938064756141700wb,
0wb) != 0wb)
__builtin_abort ();
if (baz (0wb, ~0wb) != 0wb)
__builtin_abort ();
--- a/gcc/testsuite/gcc.dg/torture/bitint-97.c 2026-04-28 08:54:25.380071489
+0200
+++ b/gcc/testsuite/gcc.dg/torture/bitint-97.c 2026-11-02 14:15:53.120759171
+0100
@@ -1,5 +1,5 @@
/* C2Y N3747 - Integer Sets, v5 */
-/* { dg-do compile { target bitint } } */
+/* { dg-do run { target bitint } } */
/* { dg-options "-std=c2y -pedantic-errors -fwrapv" } */
[[gnu::noipa]] void
@@ -24,7 +24,7 @@ main ()
};
signed _BitInt(1) g[8] = {
-1, -1, -1, -1, -1, 0, 0, -1,
- };
+ };
bar (e, f, g);
_BitInt(1) h[8] = {
0, -1, -1, -1, 0, 0, -1, -1
--- a/gcc/testsuite/gcc.dg/torture/bitint-98.c 2026-04-28 08:54:25.380165117
+0200
+++ b/gcc/testsuite/gcc.dg/torture/bitint-98.c 2026-11-02 14:16:08.734552857
+0100
@@ -1,5 +1,5 @@
/* C2Y N3747 - Integer Sets, v5 */
-/* { dg-do compile { target bitint } } */
+/* { dg-do run { target bitint } } */
/* { dg-options "-std=c2y -pedantic-errors" } */
/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */
/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
@@ -22,7 +22,6 @@ baz (_BitInt(256) x, _BitInt(256) y, _Bi
{
return __builtin_mul_overflow (x, y, z);
}
-
#endif
int
--- a/gcc/testsuite/gcc.dg/torture/bitint-99.c 2026-05-30 09:46:04.466953334
+0200
+++ b/gcc/testsuite/gcc.dg/torture/bitint-99.c 2026-11-02 14:16:14.882471619
+0100
@@ -1,5 +1,5 @@
/* C2Y N3705: bit-precise enum. */
-/* { dg-do compile { target bitint } } */
+/* { dg-do run { target bitint } } */
/* { dg-options "-std=c2y -pedantic-errors" } */
/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */
/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
Jakub