No changes intended. This refactor prepares the code so that a future
patch extending the semantic 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 | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 60ed44c2f672..32dfaf031e91 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -4059,16 +4059,19 @@ 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);
+ 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),
@@ -4076,7 +4079,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 (is_top_array_vla (TREE_TYPE (folded_expr)));
+ pop_maybe_used (is_top_array_vla (type));
}
return ret;
}
--
2.51.0