From f11ed24075538b660cd14571b87417d0ce5d2275 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 17 Nov 2022 21:47:11 +0000 Subject: [PATCH] Incorrect application of implicit condition conversion. Issue #571 --- src/names.c | 24 +++++++++++---- test/regress/operator6.vhd | 61 ++++++++++++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 test/regress/operator6.vhd diff --git a/src/names.c b/src/names.c index f812c588..2e4ff23a 100644 --- a/src/names.c +++ b/src/names.c @@ -2432,6 +2432,19 @@ static void overload_push_names(overload_t *o) o->state = O_NAMED; } +static void overload_add_argument_type(overload_t *o, type_t type, tree_t d) +{ + type_set_t *ts = o->nametab->top_type_set; + if (ts->down && ts->down->cconv && !ts->cconv) { + // Boolean interpretation should be preferred in case of ambiguity + type_t boolean = std_type(NULL, STD_BOOLEAN); + if (type_eq(type, boolean)) + ts->cconv = true; + } + + type_set_add(o->nametab, type, d); +} + static void overload_positional_argument(overload_t *o, int pos) { if (o == NULL) @@ -2450,7 +2463,7 @@ static void overload_positional_argument(overload_t *o, int pos) tree_t d = o->candidates.items[i]; if (pos < tree_ports(d)) { tree_t p = tree_port(d, pos); - type_set_add(o->nametab, tree_type(p), d); + overload_add_argument_type(o, tree_type(p), d); o->candidates.items[wptr++] = d; } else if (o->initial > 1) @@ -2511,12 +2524,13 @@ static void overload_named_argument(overload_t *o, tree_t name) if (field == NULL) continue; // Argument does not have this field name - type_set_add(o->nametab, tree_type(field), - o->candidates.items[i]); + overload_add_argument_type(o, tree_type(field), + o->candidates.items[i]); } break; default: - type_set_add(o->nametab, tree_type(p), o->candidates.items[i]); + overload_add_argument_type(o, tree_type(p), + o->candidates.items[i]); break; } port = p; @@ -2930,7 +2944,7 @@ static void solve_subprogram_params(nametab_t *tab, tree_t call, overload_t *o) } } - // Solve all remaining function call parameters + // Solve all remaining parameters which are themselves function calls for (int i = 0; i < nparams; i++) { if (pmask & (1 << i)) diff --git a/test/regress/operator6.vhd b/test/regress/operator6.vhd new file mode 100644 index 00000000..77c9ce36 --- /dev/null +++ b/test/regress/operator6.vhd @@ -0,0 +1,61 @@ +entity operator6 is +end entity; + +architecture test of operator6 is + + function "=" (L: bit; R: bit) return bit is + begin + report "custom bit =" severity failure; + return L xnor R; + end function "="; + + function "/=" (L: bit; R: bit) return bit is + begin + report "custom bit /=" severity failure; + return L xor R; + end function "/="; + + function "=" (L: bit_vector; R: bit_vector) return bit is + begin + report "custom bit_vector =" severity failure; + if L = R then + return '1'; + else + return '0'; + end if; + end function "="; + + function "/=" (L: bit_vector; R: bit_vector) return bit is + begin + report "custom bit_vector /=" severity failure; + if L /= R then + return '1'; + else + return '0'; + end if; + end function "/="; + + constant ID_FLAG_C_SHF : bit_vector(1 to 3) := "100"; + constant ID_RMW_SHF : bit := '1'; + + -- ** Note: 3972750ns+1: Report Note: bad else: s1_id_flag_c = 4 s1_id_rmw = '0' + + signal s1_id_flag_c : bit_vector(1 to 3) := ID_FLAG_C_SHF; + signal s1_id_rmw : bit := '0'; + +begin + + p1: process is + begin +-- report "bad else: s1_id_flag_c = " & integer'image(to_integer(unsigned(s1_id_flag_c))) & " s1_id_rmw = " & bit'image(to_bit(s1_id_rmw)); + if s1_id_flag_c = ID_FLAG_C_SHF then + report "s1_id_flag_c = ID_FLAG_C_SHF"; + end if; + if s1_id_rmw /= ID_RMW_SHF then + report "s1_id_rmw /= ID_RMW_SHF"; + end if; + assert s1_id_flag_c = ID_FLAG_C_SHF and s1_id_rmw /= ID_RMW_SHF; + wait; + end process; + +end architecture; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index b511d711..f22c3aaa 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -690,3 +690,4 @@ record38 fail,gold,2008 issue560 normal,2008 issue570 normal,2008 issue571 normal,2008,relaxed +operator6 normal,2008 -- 2.39.2