Hi,
Changes in v5:
- I've split the commit into two. The first one is a refactor with no
intended changes. This makes it easier to review the refactor
necessary for applying the change, and the change itself, which
becomes smaller, as both can be reviewed independently.
The interdiff is empty (see at the bottom); thus, no testing is needed,
as v4 is already tested.
Cheers,
Alex
Alejandro Colomar (2):
c: Refactor implementation of _Countof()
c: Add support for array parameters in _Countof
gcc/c/c-typeck.cc | 50 +++++++++++---
gcc/doc/extend.texi | 11 ++++
gcc/testsuite/gcc.dg/countof-compile.c | 8 +--
gcc/testsuite/gcc.dg/countof-param-compile.c | 66 +++++++++++++++++++
gcc/testsuite/gcc.dg/countof-param-pedantic.c | 11 ++++
gcc/testsuite/gcc.dg/countof-param.c | 25 +++++++
6 files changed, 156 insertions(+), 15 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/countof-param-compile.c
create mode 100644 gcc/testsuite/gcc.dg/countof-param-pedantic.c
create mode 100644 gcc/testsuite/gcc.dg/countof-param.c
Interdiff against v4:
Range-diff against v4:
-: ------------ > 1: 31191ae061c2 c: Refactor implementation of _Countof()
1: a778f22f412f ! 2: b1ca7e6c7135 c: Add support for array parameters in
_Countof
@@ gcc/c/c-typeck.cc: is_top_array_vla (tree type)
struct c_expr
@@ gcc/c/c-typeck.cc: c_expr_countof_expr (location_t loc, struct c_expr
expr)
- else
- {
- bool expr_const_operands = true;
--
-- tree folded_expr = c_fully_fold (expr.value, require_constant_value,
-- &expr_const_operands);
-- ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
-- c_last_sizeof_arg = expr.value;
-- c_last_sizeof_loc = loc;
- ret.original_code = COUNTOF_EXPR;
- ret.original_type = NULL;
- ret.m_decimal = 0;
-- if (is_top_array_vla (TREE_TYPE (folded_expr)))
-+
-+ tree folded_expr = c_fully_fold (expr.value, require_constant_value,
-+ &expr_const_operands);
-+
-+ tree type = TREE_TYPE (folded_expr);
+ &expr_const_operands);
+
+ tree type = TREE_TYPE (folded_expr);
+ if (POINTER_TYPE_P (type))
+ {
+ if (tree rv = c_array_parm_orig_type (expr.value))
@@ gcc/c/c-typeck.cc: c_expr_countof_expr (location_t loc, struct c_expr
expr)
+ }
+ }
+
-+ ret.value = c_countof_type (loc, type);
-+ c_last_sizeof_arg = expr.value;
-+ c_last_sizeof_loc = loc;
-+
-+ if (is_top_array_vla (type))
- {
- /* countof is evaluated when given a vla. */
- ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
-@@ gcc/c/c-typeck.cc: c_expr_countof_expr (location_t loc, struct c_expr
expr)
- C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
- SET_EXPR_LOCATION (ret.value, loc);
- }
-- pop_maybe_used (is_top_array_vla (TREE_TYPE (folded_expr)));
-+ pop_maybe_used (is_top_array_vla (type));
- }
- return ret;
- }
+ ret.value = c_countof_type (loc, type);
+ c_last_sizeof_arg = expr.value;
+ c_last_sizeof_loc = loc;
## gcc/doc/extend.texi ##
@@ gcc/doc/extend.texi: _Countof (int [7][n++]); // integer constant
expression
base-commit: a440b382e43203857de9195eb526c4a16f21ceb1
--
2.51.0