aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-06-27 06:36:53 +0200
committerTristan Gingold <tgingold@free.fr>2020-06-27 06:38:52 +0200
commit592602554b7f8aa1610b3bd0da33eec012983d45 (patch)
tree50fac2bee71d713d2886660cd8c7835b8184ef30 /src/ortho
parent19268309ee768de9c78f11e86071aaa9b3b28a06 (diff)
downloadghdl-592602554b7f8aa1610b3bd0da33eec012983d45.tar.gz
ghdl-592602554b7f8aa1610b3bd0da33eec012983d45.tar.bz2
ghdl-592602554b7f8aa1610b3bd0da33eec012983d45.zip
ortho/gcc/ortho-lang-9.c: fix crash with -O
Was incomplete array type for array_range_ref. For #1377
Diffstat (limited to 'src/ortho')
-rw-r--r--src/ortho/gcc/ortho-lang-9.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/ortho/gcc/ortho-lang-9.c b/src/ortho/gcc/ortho-lang-9.c
index 38bed3caa..5a5ac8859 100644
--- a/src/ortho/gcc/ortho-lang-9.c
+++ b/src/ortho/gcc/ortho-lang-9.c
@@ -1226,44 +1226,55 @@ finish_access_type (tree atype, tree dtype)
TREE_TYPE (atype) = dtype;
}
+/* Create a range type from INDEX_TYPE of length LENGTH. */
+static tree
+ortho_build_array_range(tree index_type, tree length)
+{
+ tree len;
+
+ if (integer_zerop (length))
+ {
+ /* Handle null array, by creating a one-length array... */
+ len = size_zero_node;
+ }
+ else
+ {
+ len = fold_build2 (MINUS_EXPR, index_type,
+ convert (index_type, length),
+ convert (index_type, size_one_node));
+ }
+ return build_range_type (index_type, size_zero_node, len);
+}
+
tree
new_array_type (tree el_type, tree index_type)
{
/* Incomplete array. */
tree range_type;
+ tree res;
+ /* Build an incomplete array. */
range_type = build_range_type (index_type, size_zero_node, NULL_TREE);
- return build_array_type (el_type, range_type);
+ res = build_array_type (el_type, range_type);
+ return res;
}
-
tree
new_constrained_array_type (tree atype, tree length)
{
tree range_type;
tree index_type;
- tree len;
tree res;
index_type = TYPE_DOMAIN (atype);
- if (integer_zerop (length))
- {
- /* Handle null array, by creating a one-length array... */
- len = size_zero_node;
- }
- else
- {
- len = fold_build2 (MINUS_EXPR, index_type,
- convert (index_type, length),
- convert (index_type, size_one_node));
- }
- range_type = build_range_type (index_type, size_zero_node, len);
+ range_type = ortho_build_array_range(index_type, length);
res = build_array_type (TREE_TYPE (atype), range_type);
/* Constrained arrays are *always* a subtype of its array type.
Just copy alias set. */
TYPE_ALIAS_SET (res) = get_alias_set (atype);
+
return res;
}
@@ -1407,6 +1418,14 @@ new_slice (tree arr, tree res_type, tree index)
{
gcc_assert (TREE_CODE (res_type) == ARRAY_TYPE);
+ /* gcc needs a complete array type, so create the biggest one if it is
+ not. */
+ if (TYPE_MAX_VALUE (TYPE_DOMAIN (res_type)) == NULL_TREE)
+ {
+ res_type = build_array_type (TREE_TYPE (res_type),
+ TREE_TYPE (TYPE_DOMAIN (res_type)));
+ }
+
ortho_mark_addressable (arr);
return build4 (ARRAY_RANGE_REF, res_type, arr, index, NULL_TREE, NULL_TREE);
}
@@ -1642,8 +1661,11 @@ finish_init_value (tree *decl, tree val)
TREE_STATIC (*decl) = 1;
/* The variable may be declared with an incomplete array, so be sure it
- has a completed type. */
+ has a completed type.
+ Force re-layout by clearing the size. */
+ DECL_SIZE (*decl) = NULL_TREE;
TREE_TYPE (*decl) = TREE_TYPE (val);
+ layout_decl (*decl, 0);
rest_of_decl_compilation (*decl, current_function_decl == NULL_TREE, 0);
}