https://gcc.gnu.org/g:a9981007386dd8a425f065720d71b4ecaf56e688

commit r17-5982-ga9981007386dd8a425f065720d71b4ecaf56e688
Author: Jakub Jelinek <[email protected]>
Date:   Thu Nov 5 17:32:59 2026 +0100

    testsuite: Change 4 bitint tests to dg-do run
    
    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.
    
    2026-11-05  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.
    
    Reviewed-by: Richard Biener <[email protected]>

Diff:
---
 gcc/testsuite/gcc.dg/torture/bitint-96.c | 23 +++++++++++++++--------
 gcc/testsuite/gcc.dg/torture/bitint-97.c |  4 ++--
 gcc/testsuite/gcc.dg/torture/bitint-98.c |  3 +--
 gcc/testsuite/gcc.dg/torture/bitint-99.c |  2 +-
 4 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/bitint-96.c 
b/gcc/testsuite/gcc.dg/torture/bitint-96.c
index 6589d138bbe0..77a4ebfef7b5 100644
--- a/gcc/testsuite/gcc.dg/torture/bitint-96.c
+++ b/gcc/testsuite/gcc.dg/torture/bitint-96.c
@@ -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) b[21], const 
_BitInt(1) c[21])
   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 ();
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-97.c 
b/gcc/testsuite/gcc.dg/torture/bitint-97.c
index 569b3aa56162..58c5e9ea27df 100644
--- a/gcc/testsuite/gcc.dg/torture/bitint-97.c
+++ b/gcc/testsuite/gcc.dg/torture/bitint-97.c
@@ -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
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-98.c 
b/gcc/testsuite/gcc.dg/torture/bitint-98.c
index 30aeb139e1d9..1eb86031ae9f 100644
--- a/gcc/testsuite/gcc.dg/torture/bitint-98.c
+++ b/gcc/testsuite/gcc.dg/torture/bitint-98.c
@@ -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, _BitInt(1) *z)
 {
   return __builtin_mul_overflow (x, y, z);
 }
-
 #endif
 
 int
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-99.c 
b/gcc/testsuite/gcc.dg/torture/bitint-99.c
index 1de275c066bd..ad0fdf1e9b75 100644
--- a/gcc/testsuite/gcc.dg/torture/bitint-99.c
+++ b/gcc/testsuite/gcc.dg/torture/bitint-99.c
@@ -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" } { "" } } */

Reply via email to