No changes intended. This refactor prepares the code so that a future patch extending the semantics of _Countof() will be smaller.
gcc/c/ChangeLog:
* c-typeck.cc (c_expr_countof_expr): Refactor.
Co-authored-by: Martin Uecker <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
---
gcc/c/c-typeck.cc | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 2d0200858331..61abace966da 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -4159,16 +4159,18 @@ 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 (top_array_vla_p (TREE_TYPE (folded_expr)))
+
+ tree folded_expr = c_fully_fold (expr.value, require_constant_value,
+ &expr_const_operands);
+ tree type = TREE_TYPE (folded_expr);
+ ret.value = c_countof_type (loc, type);
+
+ if (top_array_vla_p (type))
{
/* countof is evaluated when given a vla. */
ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
@@ -4176,7 +4178,7 @@ 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 (top_array_vla_p (TREE_TYPE (folded_expr)));
+ pop_maybe_used (top_array_vla_p (type));
}
return ret;
}
--
2.55.0
signature.asc
Description: PGP signature
