Hi Joseph,

I've added code handling errors from c_parser_type_name(), and added
tests for that too.

I've also applied the changes you requested about bitint tests.
For the "large" bitint tests, I tried 500.  I don't know how much would
be large, but since that is wider than intmax_t I thought it would be
enough.

See the range-diff below.

I've passed regression tests successfully:

        alx@devuan:~/src/gnu/gcc/maxof$ git tag maxof6
        alx@devuan:~/src/gnu/gcc/maxof$ git log --oneline gnu/master^..maxof6
        00aab1fbde52 (HEAD -> maxof, tag: maxof6) c: Add _Maxof and _Minof 
operators
        59a5fecfb260 (gnu/trunk, gnu/master, gnu/HEAD) aarch64: Extract 
aarch64_indirect_branch_asm for sibcall codegen
        alx@devuan:~/src/gnu/gcc/maxof$ git reset gnu/master --h
        HEAD is now at 59a5fecfb260 aarch64: Extract 
aarch64_indirect_branch_asm for sibcall codegen
        alx@devuan:~/src/gnu/gcc/maxof$ mkdir ../maxof6
        alx@devuan:~/src/gnu/gcc/maxof$ cd ../maxof6/
        alx@devuan:~/src/gnu/gcc/maxof6$ set -o pipefail
        alx@devuan:~/src/gnu/gcc/maxof6$ ../maxof/configure --disable-multilib 
--prefix=/opt/local/gnu/gcc/maxof6 |& ts -s | tail -n1; echo $?; make -j24 
bootstrap |& ts -s | tail -n1; echo $?; make -j24 check |& ts -s | tail -n1; 
echo $?;
        00:00:02 config.status: creating Makefile
        0
        00:21:47 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof6'
        0
        00:35:33 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof6'
        0
        alx@devuan:~/src/gnu/gcc/maxof6$ cd ../maxof
        alx@devuan:~/src/gnu/gcc/maxof$ git merge --ff-only maxof6
        Updating 59a5fecfb260..00aab1fbde52
        Fast-forward
         gcc/c-family/c-common.cc                     |  32 ++++
         gcc/c-family/c-common.def                    |   6 +
         gcc/c-family/c-common.h                      |   4 +-
         gcc/c/c-parser.cc                            |  70 ++++++++-
         gcc/c/c-tree.h                               |   2 +
         gcc/c/c-typeck.cc                            |  54 +++++++
         gcc/doc/extend.texi                          |  19 +++
         gcc/testsuite/gcc.dg/maxof-bitint.c          |  20 +++
         gcc/testsuite/gcc.dg/maxof-bitint575.c       |  39 +++++
         gcc/testsuite/gcc.dg/maxof-compile.c         | 151 +++++++++++++++++++
         gcc/testsuite/gcc.dg/maxof-pedantic-errors.c |   5 +
         gcc/testsuite/gcc.dg/maxof-pedantic.c        |   5 +
         12 files changed, 405 insertions(+), 2 deletions(-)
         create mode 100644 gcc/testsuite/gcc.dg/maxof-bitint.c
         create mode 100644 gcc/testsuite/gcc.dg/maxof-bitint575.c
         create mode 100644 gcc/testsuite/gcc.dg/maxof-compile.c
         create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic-errors.c
         create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic.c
        alx@devuan:~/src/gnu/gcc/maxof$ cd ../
        alx@devuan:~/src/gnu/gcc$ mv maxof6/ maxof6_b4
        alx@devuan:~/src/gnu/gcc$ mkdir maxof6
        alx@devuan:~/src/gnu/gcc$ cd maxof6
        alx@devuan:~/src/gnu/gcc/maxof6$ ../maxof/configure --disable-multilib 
--prefix=/opt/local/gnu/gcc/maxof6 |& ts -s | tail -n1; echo $?; make -j24 
bootstrap |& ts -s | tail -n1; echo $?; make -j24 check |& ts -s | tail -n1; 
echo $?;
        00:00:01 config.status: creating Makefile
        0
        00:26:47 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof6'
        0
        00:40:09 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof6'
        0
        alx@devuan:~/src/gnu/gcc/maxof6$ find -type f | grep '\.sum$' | while 
read f; do diff -u "../maxof6_b4/$f" "$f"; done;
        --- ../maxof6_b4/./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum      
2025-11-22 08:03:58.028562799 +0100
        +++ ./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum   2025-11-22 
20:03:41.359106503 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:55 2025
        +Test run by alx on Sat Nov 22 20:03:38 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libitm tests ===
        --- 
../maxof6_b4/./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum2025-11-22 
08:03:56.936461832 +0100
        +++ ./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum     
2025-11-22 20:03:40.303734575 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:55 2025
        +Test run by alx on Sat Nov 22 20:03:38 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libatomic tests ===
        --- ../maxof6_b4/./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum    
2025-11-22 08:06:50.520063623 +0100
        +++ ./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum 2025-11-22 
20:06:41.977060148 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:55 2025
        +Test run by alx on Sat Nov 22 20:03:38 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libgomp tests ===
        --- 
../maxof6_b4/./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum     
2025-11-22 08:39:27.237817007 +0100
        +++ ./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum  
2025-11-22 20:43:47.470748111 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:56 2025
        +Test run by alx on Sat Nov 22 20:03:39 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libstdc++ tests ===
        --- ../maxof6_b4/./gcc/testsuite/objc/objc.sum  2025-11-22 
08:04:22.974338392 +0100
        +++ ./gcc/testsuite/objc/objc.sum       2025-11-22 20:05:16.184053767 
+0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:56 2025
        +Test run by alx on Sat Nov 22 20:03:39 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === objc tests ===
        --- ../maxof6_b4/./gcc/testsuite/g++/g++.sum    2025-11-22 
08:16:26.012151680 +0100
        +++ ./gcc/testsuite/g++/g++.sum 2025-11-22 20:23:44.279906496 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:56 2025
        +Test run by alx on Sat Nov 22 20:03:39 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === g++ tests ===
        --- ../maxof6_b4/./gcc/testsuite/gcc/gcc.sum    2025-11-22 
08:21:20.793851354 +0100
        +++ ./gcc/testsuite/gcc/gcc.sum 2025-11-22 20:27:47.550027364 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:56 2025
        +Test run by alx on Sat Nov 22 20:03:39 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === gcc tests ===
        @@ -94161,6 +94161,44 @@
         PASS: gcc.dg/max-1.c execution test
         PASS: gcc.dg/max.c (test for excess errors)
         PASS: gcc.dg/max.c scan-tree-dump-not optimized "MAX_EXPR"
        +PASS: gcc.dg/maxof-bitint.c (test for excess errors)
        +PASS: gcc.dg/maxof-bitint575.c (test for excess errors)
        +PASS: gcc.dg/maxof-bitint575.c execution test
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 102)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 104)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 106)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 107)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 113)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 114)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 115)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 116)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 71)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 73)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 75)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 77)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 79)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 80)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 81)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 82)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 91)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 92)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 93)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 94)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 95)
        +PASS: gcc.dg/maxof-compile.c  (test for errors, line 96)
        +PASS: gcc.dg/maxof-compile.c (test for excess errors)
        +PASS: gcc.dg/maxof-compile.c syntax error at line 103 (test for 
errors, line 102)
        +PASS: gcc.dg/maxof-compile.c syntax error at line 105 (test for 
errors, line 104)
        +PASS: gcc.dg/maxof-compile.c syntax error at line 72 (test for errors, 
line 71)
        +PASS: gcc.dg/maxof-compile.c syntax error at line 74 (test for errors, 
line 73)
        +PASS: gcc.dg/maxof-compile.c syntax error at line 76 (test for errors, 
line 75)
        +PASS: gcc.dg/maxof-compile.c syntax error at line 78 (test for errors, 
line 77)
        +PASS: gcc.dg/maxof-pedantic-errors.c  (test for errors, line 4)
        +PASS: gcc.dg/maxof-pedantic-errors.c  (test for errors, line 5)
        +PASS: gcc.dg/maxof-pedantic-errors.c (test for excess errors)
        +PASS: gcc.dg/maxof-pedantic.c  (test for warnings, line 4)
        +PASS: gcc.dg/maxof-pedantic.c  (test for warnings, line 5)
        +PASS: gcc.dg/maxof-pedantic.c (test for excess errors)
         PASS: gcc.dg/memchr-2.c (test for excess errors)
         PASS: gcc.dg/memchr-2.c scan-tree-dump-not optimized "abort"
         PASS: gcc.dg/memchr-2.c scan-tree-dump-not optimized "memcmp \\("
        @@ -221153,7 +221191,7 @@
         
                        === gcc Summary ===
         
        -# of expected passes           215080
        +# of expected passes           215118
         # of unexpected failures       529
         # of unexpected successes      6
         # of expected failures         1486
        --- ../maxof6_b4/./gcc/testsuite/gfortran/gfortran.sum  2025-11-22 
08:15:18.737230124 +0100
        +++ ./gcc/testsuite/gfortran/gfortran.sum       2025-11-22 
20:22:26.369034475 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Sat Nov 22 08:03:56 2025
        +Test run by alx on Sat Nov 22 20:03:39 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === gfortran tests ===


Have a lovely night!
Alex


Alejandro Colomar (1):
  c: Add _Maxof and _Minof operators

 gcc/c-family/c-common.cc                     |  32 ++++
 gcc/c-family/c-common.def                    |   6 +
 gcc/c-family/c-common.h                      |   4 +-
 gcc/c/c-parser.cc                            |  70 ++++++++-
 gcc/c/c-tree.h                               |   2 +
 gcc/c/c-typeck.cc                            |  54 +++++++
 gcc/doc/extend.texi                          |  19 +++
 gcc/testsuite/gcc.dg/maxof-bitint.c          |  20 +++
 gcc/testsuite/gcc.dg/maxof-bitint575.c       |  39 +++++
 gcc/testsuite/gcc.dg/maxof-compile.c         | 151 +++++++++++++++++++
 gcc/testsuite/gcc.dg/maxof-pedantic-errors.c |   5 +
 gcc/testsuite/gcc.dg/maxof-pedantic.c        |   5 +
 12 files changed, 405 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/maxof-bitint.c
 create mode 100644 gcc/testsuite/gcc.dg/maxof-bitint575.c
 create mode 100644 gcc/testsuite/gcc.dg/maxof-compile.c
 create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic-errors.c
 create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic.c

Range-diff against v5:
1:  ef68a32a2bd5 ! 1:  00aab1fbde52 c: Add _Maxof and _Minof operators
    @@ Commit message
     
         gcc/testsuite/ChangeLog:
     
    +            * gcc.dg/maxof-bitint.c: New test.
    +            * gcc.dg/maxof-bitint575.c: New test.
                 * gcc.dg/maxof-compile.c: New test.
                 * gcc.dg/maxof-pedantic-errors.c: New test.
                 * gcc.dg/maxof-pedantic.c: New test.
    @@ gcc/c/c-parser.cc: c_parser_alignof_expression (c_parser *parser)
     +      goto fail;
     +    }
     +  type_name = c_parser_type_name (parser, true);
    -+  // Can return NULL?  Why?
    ++  if (type_name == NULL)
    ++    {
    ++      // c_parser_type_name() has already diagnosed the error.
    ++      parens.skip_until_found_close (parser);
    ++      goto fail;
    ++    }
     +  parens.skip_until_found_close (parser);
     +  finish = parser->tokens_buf[0].location;
     +  if (type_name->specs->alignas_p)
    @@ gcc/doc/extend.texi: _Countof (int [7][n++]);  // integer constant 
expression
      @subsection Support for @code{offsetof}
      @findex __builtin_offsetof
     
    + ## gcc/testsuite/gcc.dg/maxof-bitint.c (new) ##
    +@@
    ++/* { dg-do compile { target bitint } } */
    ++/* { dg-options "-std=gnu2y" } */
    ++
    ++void
    ++limits (void)
    ++{
    ++  _Static_assert (_Maxof (_BitInt (5)) == 15);
    ++  _Static_assert (_Minof (_BitInt (5)) == -16);
    ++  _Static_assert (_Maxof (unsigned _BitInt (5)) == 31);
    ++  _Static_assert (_Minof (unsigned _BitInt (5)) == 0);
    ++}
    ++
    ++void
    ++type (void)
    ++{
    ++  _Generic (_Maxof (_BitInt (5)), _BitInt (5): 0);
    ++  _Generic (_Minof (_BitInt (5)), _BitInt (5): 0);
    ++  _Generic (_Maxof (unsigned _BitInt (5)), unsigned _BitInt (5): 0);
    ++  _Generic (_Minof (unsigned _BitInt (5)), unsigned _BitInt (5): 0);
    ++}
    +
    + ## gcc/testsuite/gcc.dg/maxof-bitint575.c (new) ##
    +@@
    ++/* { dg-do run { target bitint575 } } */
    ++/* { dg-options "-std=gnu2y" } */
    ++
    ++#define assert(e)  ((e) ? (void) 0 : __builtin_abort ())
    ++
    ++void limits (void);
    ++
    ++int
    ++main (void)
    ++{
    ++  limits ();
    ++}
    ++
    ++void
    ++limits (void)
    ++{
    ++  unsigned _BitInt (500) u;
    ++  _BitInt (500) i;
    ++
    ++  u = 0;
    ++  u--;
    ++
    ++  assert (_Maxof (unsigned _BitInt (500)) == u);
    ++  assert (_Minof (unsigned _BitInt (500)) == 0);
    ++
    ++  i = u >> 1;
    ++
    ++  assert (_Maxof (_BitInt (500)) == i);
    ++  assert (_Minof (_BitInt (500)) == -i-1);
    ++}
    ++
    ++void
    ++type (void)
    ++{
    ++  _Generic (_Maxof (_BitInt (500)), _BitInt (500): 0);
    ++  _Generic (_Minof (_BitInt (500)), _BitInt (500): 0);
    ++  _Generic (_Maxof (unsigned _BitInt (500)), unsigned _BitInt (500): 0);
    ++  _Generic (_Minof (unsigned _BitInt (500)), unsigned _BitInt (500): 0);
    ++}
    +
      ## gcc/testsuite/gcc.dg/maxof-compile.c (new) ##
     @@
     +/* { dg-do compile } */
    @@ gcc/testsuite/gcc.dg/maxof-compile.c (new)
     +}
     +
     +void
    -+bitint (void)
    -+{
    -+  _Static_assert (_Maxof (_BitInt (5)) == 15);
    -+  _Static_assert (_Minof (_BitInt (5)) == -16);
    -+  _Static_assert (_Maxof (unsigned _BitInt (5)) == 31);
    -+  _Static_assert (_Minof (unsigned _BitInt (5)) == 0);
    -+}
    -+
    -+void
     +enums (void)
     +{
     +  enum e1 { E1 };
    @@ gcc/testsuite/gcc.dg/maxof-compile.c (new)
     +{
     +  _Maxof (int x);  /* { dg-error "expected '\\)'" } */
     +  _Minof (int x);  /* { dg-error "expected '\\)'" } */
    ++  _Maxof (int (!));  /* { dg-error "expected '\\)'" } */
    ++  _Minof (int (!));  /* { dg-error "expected '\\)'" } */
     +}
     +
     +void
    @@ gcc/testsuite/gcc.dg/maxof-compile.c (new)
     +
     +  _Generic (_Maxof (bool), bool: 0);
     +  _Generic (_Minof (bool), bool: 0);
    -+
    -+  _Generic (_Maxof (_BitInt (5)), _BitInt (5): 0);
    -+  _Generic (_Minof (_BitInt (5)), _BitInt (5): 0);
    -+  _Generic (_Maxof (unsigned _BitInt (5)), unsigned _BitInt (5): 0);
    -+  _Generic (_Minof (unsigned _BitInt (5)), unsigned _BitInt (5): 0);
     +}
     
      ## gcc/testsuite/gcc.dg/maxof-pedantic-errors.c (new) ##
-- 
2.51.0

Reply via email to