diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-06-27 06:40:45 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-06-27 06:40:45 +0200 |
commit | 0e98271e5137b0377ad5c1ecc6eb404b2960f98e (patch) | |
tree | 01c49ccd887021c35ad5267958b4ab62e16a1697 /src/ortho/gcc/ortho-lang-5.c | |
parent | 592602554b7f8aa1610b3bd0da33eec012983d45 (diff) | |
download | ghdl-0e98271e5137b0377ad5c1ecc6eb404b2960f98e.tar.gz ghdl-0e98271e5137b0377ad5c1ecc6eb404b2960f98e.tar.bz2 ghdl-0e98271e5137b0377ad5c1ecc6eb404b2960f98e.zip |
ortho/gcc: apply previous patch to all gcc versions.
Diffstat (limited to 'src/ortho/gcc/ortho-lang-5.c')
-rw-r--r-- | src/ortho/gcc/ortho-lang-5.c | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/ortho/gcc/ortho-lang-5.c b/src/ortho/gcc/ortho-lang-5.c index 140a4a370..6dedb14b0 100644 --- a/src/ortho/gcc/ortho-lang-5.c +++ b/src/ortho/gcc/ortho-lang-5.c @@ -1213,44 +1213,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; } @@ -1394,6 +1405,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); } @@ -1629,8 +1648,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); } |