Hi!

Here's another revision of this patch set.

v23 changes:

-  More specific change logs.
-  #define assert() instead of #include'ing <assert.h>.

`make check` says all's good.  I haven't diffed against master this
time, because that's slow as hell, and the changes are minimal.  I've
only ran `make check -j24` once at the tip, and all the countof tests
pass.


Have a lovely night!
Alex


Alejandro Colomar (3):
  c: Add _Countof operator
  c: Add <stdcountof.h>
  c: Add -Wpedantic diagnostic for _Countof

 gcc/Makefile.in                               |   1 +
 gcc/c-family/c-common.cc                      |  26 ++++
 gcc/c-family/c-common.def                     |   3 +
 gcc/c-family/c-common.h                       |   2 +
 gcc/c/c-decl.cc                               |  22 +++-
 gcc/c/c-parser.cc                             |  63 +++++++--
 gcc/c/c-tree.h                                |   4 +
 gcc/c/c-typeck.cc                             | 115 +++++++++++++++-
 gcc/doc/extend.texi                           |  30 +++++
 gcc/ginclude/stdcountof.h                     |  31 +++++
 gcc/testsuite/gcc.dg/countof-compat.c         |   8 ++
 gcc/testsuite/gcc.dg/countof-compile.c        | 124 ++++++++++++++++++
 gcc/testsuite/gcc.dg/countof-no-compat.c      |   5 +
 .../gcc.dg/countof-pedantic-errors.c          |   8 ++
 gcc/testsuite/gcc.dg/countof-pedantic.c       |   8 ++
 gcc/testsuite/gcc.dg/countof-stdcountof.c     |  24 ++++
 gcc/testsuite/gcc.dg/countof-vla.c            |  35 +++++
 gcc/testsuite/gcc.dg/countof-vmt.c            |  20 +++
 gcc/testsuite/gcc.dg/countof-zero-compile.c   |  38 ++++++
 gcc/testsuite/gcc.dg/countof-zero.c           |  31 +++++
 gcc/testsuite/gcc.dg/countof.c                | 120 +++++++++++++++++
 21 files changed, 694 insertions(+), 24 deletions(-)
 create mode 100644 gcc/ginclude/stdcountof.h
 create mode 100644 gcc/testsuite/gcc.dg/countof-compat.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-compile.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-no-compat.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-pedantic-errors.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-pedantic.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-stdcountof.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-vla.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-vmt.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-zero-compile.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/countof.c

Range-diff against v22:
1:  1c983c3baa7f ! 1:  5040a7d25a96 c: Add _Countof operator
    @@ Commit message
     
         gcc/c-family/ChangeLog:
     
    -            * c-common.h
    -            * c-common.def
    -            * c-common.cc (c_countof_type): Add _Countof operator.
    +            * c-common.h: Add RID_COUNTOF.
    +            (c_countof_type): New function prototype.
    +            * c-common.def (COUNTOF_EXPR): New tree.
    +            * c-common.cc
    +            (c_common_reswords): Add RID_COUNTOF entry.
    +            (c_countof_type): New function.
     
         gcc/c/ChangeLog:
     
                 * c-tree.h
    -            (c_expr_countof_expr, c_expr_countof_type)
    +            (in_countof): Add global variable declaration.
    +            (c_expr_countof_expr): Add function prototype.
    +            (c_expr_countof_type): Add function prototype.
                 * c-decl.cc
    -            (start_struct, finish_struct)
    -            (start_enum, finish_enum)
    +            (start_struct, finish_struct): Add support for _Countof.
    +            (start_enum, finish_enum): Add support for _Countof.
                 * c-parser.cc
    -            (c_parser_sizeof_expression)
    -            (c_parser_countof_expression)
    -            (c_parser_sizeof_or_countof_expression)
    -            (c_parser_unary_expression)
    +            (c_parser_sizeof_expression): New macro.
    +            (c_parser_countof_expression): New macro.
    +            (c_parser_sizeof_or_countof_expression):
    +            Rename function and add support for _Countof.
    +            (c_parser_unary_expression): Add RID_COUNTOF entry.
                 * c-typeck.cc
    -            (build_external_ref)
    -            (record_maybe_used_decl)
    -            (pop_maybe_used)
    -            (is_top_array_vla)
    -            (c_expr_countof_expr, c_expr_countof_type):
    +            (in_countof): Add global variable.
    +            (build_external_ref): Add support for _Countof.
    +            (record_maybe_used_decl): Add support for _Countof.
    +            (pop_maybe_used): Add support for _Countof.
    +            (is_top_array_vla): New function.
    +            (c_expr_countof_expr, c_expr_countof_type): New functions.
                 Add _Countof operator.
     
         gcc/testsuite/ChangeLog:
     
    -            * gcc.dg/countof-compile.c
    -            * gcc.dg/countof-vla.c
    -            * gcc.dg/countof-vmt.c
    -            * gcc.dg/countof-zero-compile.c
    -            * gcc.dg/countof-zero.c
    -            * gcc.dg/countof.c: Add tests for _Countof operator.
    +            * gcc.dg/countof-compile.c: Compile-time tests for _Countof.
    +            * gcc.dg/countof-vla.c: Tests for _Countof with VLAs.
    +            * gcc.dg/countof-vmt.c: Tests for _Countof with other VMTs.
    +            * gcc.dg/countof-zero-compile.c:
    +            Compile-time tests for _Countof with zero-sized arrays.
    +            * gcc.dg/countof-zero.c:
    +            Tests for _Countof with zero-sized arrays.
    +            * gcc.dg/countof.c: Tests for _Countof.
     
         Suggested-by: Xavier Del Campo Romero <xavi....@tutanota.com>
         Co-authored-by: Martin Uecker <uec...@tugraz.at>
    @@ gcc/testsuite/gcc.dg/countof-vmt.c (new)
     +/* { dg-do run } */
     +/* { dg-options "-std=c2y" } */
     +
    -+#undef NDEBUG
    -+#include <assert.h>
    ++#define assert(e)  ((e) ? (void) 0 : __builtin_abort ())
     +
     +void
     +inner_vla_noeval (void)
    @@ gcc/testsuite/gcc.dg/countof-zero.c (new)
     +/* { dg-do run } */
     +/* { dg-options "-std=c2y" } */
     +
    -+#undef NDEBUG
    -+#include <assert.h>
    ++#define assert(e)  ((e) ? (void) 0 : __builtin_abort ())
     +
     +void
     +vla (void)
    @@ gcc/testsuite/gcc.dg/countof.c (new)
     +/* { dg-do run } */
     +/* { dg-options "-std=c2y -pedantic-errors" } */
     +
    -+#undef NDEBUG
    -+#include <assert.h>
    ++#define assert(e)  ((e) ? (void) 0 : __builtin_abort ())
     +
     +void
     +array (void)
2:  418f81175e78 ! 2:  a560cf1ae23b c: Add <stdcountof.h>
    @@ gcc/testsuite/gcc.dg/countof-stdcountof.c (new)
     +
     +#include <stdcountof.h>
     +
    -+#undef NDEBUG
    -+#include <assert.h>
    ++#define assert(e)  ((e) ? (void) 0 : __builtin_abort ())
     +
     +extern int strcmp (const char *, const char *);
     +
3:  c44ef4a2c751 ! 3:  b1974a4507bc c: Add -Wpedantic diagnostic for _Countof
    @@ Commit message
     
         gcc/testsuite/ChangeLog:
     
    -            * gcc.dg/countof-compat.c
    -            * gcc.dg/countof-no-compat.c
    -            * gcc.dg/countof-pedantic.c
    +            * gcc.dg/countof-compat.c:
    +            Test _Countof diagnostics with -Wc23-c2y-compat on C2y.
    +            * gcc.dg/countof-no-compat.c:
    +            Test _Countof diagnostics with -Wno-c23-c2y-compat on C23.
    +            * gcc.dg/countof-pedantic.c:
    +            Test _Countof diagnostics with -pedantic on C23.
                 * gcc.dg/countof-pedantic-errors.c:
    -            Test pedantic diagnostics for _Countof.
    +            Test _Countof diagnostics with -pedantic-errors on C23.
     
         Signed-off-by: Alejandro Colomar <a...@kernel.org>
     

base-commit: 90c6ccebd762ae920690fce20cd3f2b8e24357a7
-- 
2.49.0

Reply via email to