aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r--gcc/cp/init.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 9e582d66e3e..fccd2896a87 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -175,9 +175,9 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
initialized are initialized to zero. */
;
else if (TYPE_PTR_OR_PTRMEM_P (type))
- init = convert (type, nullptr_node);
+ init = fold (convert (type, nullptr_node));
else if (SCALAR_TYPE_P (type))
- init = convert (type, integer_zero_node);
+ init = fold (convert (type, integer_zero_node));
else if (RECORD_OR_UNION_CODE_P (TREE_CODE (type)))
{
tree field;
@@ -2558,6 +2558,11 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
outer_nelts_from_type = true;
}
+ /* Lots of logic below. depends on whether we have a constant number of
+ elements, so go ahead and fold it now. */
+ if (outer_nelts)
+ outer_nelts = maybe_constant_value (outer_nelts);
+
/* If our base type is an array, then make sure we know how many elements
it has. */
for (elt_type = type;
@@ -2608,7 +2613,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
/* Warn if we performed the (T[N]) to T[N] transformation and N is
variable. */
if (outer_nelts_from_type
- && !TREE_CONSTANT (maybe_constant_value (outer_nelts)))
+ && !TREE_CONSTANT (outer_nelts))
{
if (complain & tf_warning_or_error)
{
@@ -2708,7 +2713,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
max_outer_nelts = wi::udiv_trunc (max_size, inner_size);
max_outer_nelts_tree = wide_int_to_tree (sizetype, max_outer_nelts);
- size = size_binop (MULT_EXPR, size, convert (sizetype, nelts));
+ size = size_binop (MULT_EXPR, size, fold_convert (sizetype, nelts));
if (TREE_CONSTANT (outer_nelts))
{
@@ -2897,7 +2902,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
{
placement_expr = get_target_expr (placement_first);
CALL_EXPR_ARG (alloc_call, 1)
- = convert (TREE_TYPE (placement), placement_expr);
+ = fold_convert (TREE_TYPE (placement), placement_expr);
}
if (!member_new_p
@@ -3506,7 +3511,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
/* The below is short by the cookie size. */
virtual_size = size_binop (MULT_EXPR, size_exp,
- convert (sizetype, maxindex));
+ fold_convert (sizetype, maxindex));
tbase = create_temporary_var (ptype);
tbase_init
@@ -3549,7 +3554,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
/* The below is short by the cookie size. */
virtual_size = size_binop (MULT_EXPR, size_exp,
- convert (sizetype, maxindex));
+ fold_convert (sizetype, maxindex));
if (! TYPE_VEC_NEW_USES_COOKIE (type))
/* no header */
@@ -3595,8 +3600,8 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
body = fold_build3_loc (input_location, COND_EXPR, void_type_node,
fold_build2_loc (input_location,
NE_EXPR, boolean_type_node, base,
- convert (TREE_TYPE (base),
- nullptr_node)),
+ fold_convert (TREE_TYPE (base),
+ nullptr_node)),
body, integer_zero_node);
body = build1 (NOP_EXPR, void_type_node, body);
@@ -3718,6 +3723,7 @@ build_vec_init (tree base, tree maxindex, tree init,
if (maxindex == NULL_TREE || maxindex == error_mark_node)
return error_mark_node;
+ maxindex = maybe_constant_value (maxindex);
if (explicit_value_init_p)
gcc_assert (!init);
@@ -3759,6 +3765,8 @@ build_vec_init (tree base, tree maxindex, tree init,
}
maxindex = cp_convert (ptrdiff_type_node, maxindex, complain);
+ maxindex = fold_simple (maxindex);
+
if (TREE_CODE (atype) == ARRAY_TYPE)
{
ptype = build_pointer_type (type);