From b9d10832b8d5f8a5c372a09aabeebd378c060493 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 23 Dec 2023 21:00:37 +0000 Subject: [PATCH] Do not allow 'VALUE and 'IMAGE for non-scalar types prior to 2019 --- src/lower.c | 4 +--- src/sem.c | 10 +++++++--- test/sem/lcs2016_18.vhd | 1 + test/test_sem.c | 6 ++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lower.c b/src/lower.c index 52c62f76..0c87c47c 100644 --- a/src/lower.c +++ b/src/lower.c @@ -9164,9 +9164,7 @@ static void lower_array_value_helper(lower_unit_t *lu, type_t type, vcode_type_t voffset = vtype_offset(); vcode_type_t ctype = vtype_char(); vcode_type_t strtype = vtype_uarray(1, ctype, ctype); - - // TODO: this should not be called before 2019 - vcode_type_t vnat = vtype_int(0, standard() < STD_19 ? INT32_MAX : INT64_MAX); + vcode_type_t vnat = vtype_int(0, INT64_MAX); vcode_reg_t locus = lower_debug_locus(decl); diff --git a/src/sem.c b/src/sem.c index 8e783060..bf8136d0 100644 --- a/src/sem.c +++ b/src/sem.c @@ -4133,8 +4133,9 @@ static bool sem_check_attr_ref(tree_t t, bool allow_range, nametab_t *tab) case ATTR_IMAGE: case ATTR_VALUE: { - if (named_type == NULL && standard() >= STD_19 - && tree_params(t) == 0) { + const bool std_2019 = standard() >= STD_19; + + if (named_type == NULL && std_2019 && tree_params(t) == 0) { // LCS2016-18 allows attribute with object prefix named_type = get_type_or_null(name); add_param(t, name, P_POS, NULL); @@ -4142,7 +4143,10 @@ static bool sem_check_attr_ref(tree_t t, bool allow_range, nametab_t *tab) if (named_type == NULL) sem_error(t, "prefix of attribute %s must be a type", istr(attr)); - else if (!type_is_representable(named_type)) + if (!std_2019 && !type_is_scalar(named_type)) + sem_error(t, "cannot use attribute %s with non-scalar type %s", + istr(attr), type_pp(named_type)); + else if (std_2019 && !type_is_representable(named_type)) sem_error(t, "cannot use attribute %s with non-representable " "type %s", istr(attr), type_pp(named_type)); diff --git a/test/sem/lcs2016_18.vhd b/test/sem/lcs2016_18.vhd index 463926bb..22d4d907 100644 --- a/test/sem/lcs2016_18.vhd +++ b/test/sem/lcs2016_18.vhd @@ -38,6 +38,7 @@ begin report p3'image; -- Error assert x'left = integer'left; -- OK report y'length; -- Error + report file_of_int'image(3); -- Error end process; end architecture; diff --git a/test/test_sem.c b/test/test_sem.c index 29bda6c2..a71f92dc 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -712,14 +712,14 @@ START_TEST(test_attr) { 159, "object B does not have a range" }, { 160, "prefix does not have a range" }, { 204, "prefix does not have LENGTH attribute" }, - { 212, "cannot use attribute IMAGE with non-representable type INT2_" }, + { 212, "cannot use attribute IMAGE with non-scalar type INT2_" }, { 221, "prefix of 'BASE attribute must be a type or subtype declara" }, { 222, "BASE attribute is allowed only as the prefix of the name" }, { 228, "no visible declaration for NOT_HERE" }, { 251, "parameter of attribute VAL must have an integer type but " "found universal_real" }, { 252, "attribute VAL requires a parameter" }, - { 260, "cannot use attribute VALUE with non-representable type BIT2D" }, + { 260, "cannot use attribute VALUE with non-scalar type BIT2D" }, { 303, "expression must be a BOOLEAN literal" }, { 305, "NEVER_WAITS attribute can only be applied to procedures" }, { 309, "failed to parse FOREIGN attribute" }, @@ -3099,6 +3099,8 @@ START_TEST(test_lcs2016_18) { 38, "prefix of attribute IMAGE must be a type" }, { 40, "prefix of attribute LENGTH must be an array or a discrete " "type but have type REAL" }, + { 41, "cannot use attribute IMAGE with non-representable type " + "FILE_OF_INT" }, { -1, NULL } }; expect_errors(expect); -- 2.39.2