aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 9c67bea..fa7646b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -1790,34 +1790,66 @@ build_vector_from_val (tree vectype, tree sc)
}
}
-/* Return a new CONSTRUCTOR node whose type is TYPE and whose values
- are in the vec pointed to by VALS. */
-tree
-build_constructor (tree type, vec<constructor_elt, va_gc> *vals)
+/* Something has messed with the elements of CONSTRUCTOR C after it was built;
+ calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
+
+void
+recompute_constructor_flags (tree c)
{
- tree c = make_node (CONSTRUCTOR);
unsigned int i;
- constructor_elt *elt;
+ tree val;
bool constant_p = true;
bool side_effects_p = false;
+ vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
- TREE_TYPE (c) = type;
- CONSTRUCTOR_ELTS (c) = vals;
-
- FOR_EACH_VEC_SAFE_ELT (vals, i, elt)
+ FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
{
/* Mostly ctors will have elts that don't have side-effects, so
the usual case is to scan all the elements. Hence a single
loop for both const and side effects, rather than one loop
each (with early outs). */
- if (!TREE_CONSTANT (elt->value))
+ if (!TREE_CONSTANT (val))
constant_p = false;
- if (TREE_SIDE_EFFECTS (elt->value))
+ if (TREE_SIDE_EFFECTS (val))
side_effects_p = true;
}
TREE_SIDE_EFFECTS (c) = side_effects_p;
TREE_CONSTANT (c) = constant_p;
+}
+
+/* Make sure that TREE_CONSTANT and TREE_SIDE_EFFECTS are correct for
+ CONSTRUCTOR C. */
+
+void
+verify_constructor_flags (tree c)
+{
+ unsigned int i;
+ tree val;
+ bool constant_p = TREE_CONSTANT (c);
+ bool side_effects_p = TREE_SIDE_EFFECTS (c);
+ vec<constructor_elt, va_gc> *vals = CONSTRUCTOR_ELTS (c);
+
+ FOR_EACH_CONSTRUCTOR_VALUE (vals, i, val)
+ {
+ if (constant_p && !TREE_CONSTANT (val))
+ internal_error ("non-constant element in constant CONSTRUCTOR");
+ if (!side_effects_p && TREE_SIDE_EFFECTS (val))
+ internal_error ("side-effects element in no-side-effects CONSTRUCTOR");
+ }
+}
+
+/* Return a new CONSTRUCTOR node whose type is TYPE and whose values
+ are in the vec pointed to by VALS. */
+tree
+build_constructor (tree type, vec<constructor_elt, va_gc> *vals)
+{
+ tree c = make_node (CONSTRUCTOR);
+
+ TREE_TYPE (c) = type;
+ CONSTRUCTOR_ELTS (c) = vals;
+
+ recompute_constructor_flags (c);
return c;
}