From 720e790f21efcdaa98576d4dbc26050c3a5422af Mon Sep 17 00:00:00 2001
From: Tristan Gingold <tgingold@free.fr>
Date: Thu, 2 Jan 2014 00:24:53 +0100
Subject: Fix bug7186: missing check in Sem_Parenthesis_Name for non-overloaded
 case.

---
 sem_names.adb                      | 63 ++++++++++++++++++++------------------
 testsuite/gna/bug7186/bug.vhdl     | 24 +++++++++++++++
 testsuite/gna/bug7186/testsuite.sh |  9 ++++++
 3 files changed, 67 insertions(+), 29 deletions(-)
 create mode 100644 testsuite/gna/bug7186/bug.vhdl
 create mode 100755 testsuite/gna/bug7186/testsuite.sh

diff --git a/sem_names.adb b/sem_names.adb
index 89e8dfd86..0e46db97c 100644
--- a/sem_names.adb
+++ b/sem_names.adb
@@ -1877,6 +1877,38 @@ package body Sem_Names is
          return R;
       end Sem_As_Indexed_Or_Slice_Name;
 
+      --  Sem parenthesis name when the prefix is a function declaration.
+      --  Can be either a function call (and the expression is the actual) or
+      --  a slice/index of the result of a call without actual.
+      procedure Sem_Parenthesis_Function (Sub_Name : Iir) is
+         Used : Boolean;
+         R : Iir;
+         Match : Boolean;
+      begin
+         Used := False;
+         if Get_Kind (Sub_Name) in Iir_Kinds_Function_Declaration then
+            Sem_Association_Chain
+              (Get_Interface_Declaration_Chain (Sub_Name),
+               Assoc_Chain, False, Missing_Parameter, Name, Match);
+            if Match then
+               Add_Result
+                 (Res,
+                  Sem_As_Function_Call (Prefix_Name, Sub_Name, Assoc_Chain));
+               Used := True;
+            end if;
+         end if;
+         if Get_Kind (Sub_Name) not in Iir_Kinds_Procedure_Declaration then
+            R := Sem_As_Indexed_Or_Slice_Name (Sub_Name, False);
+            if R /= Null_Iir then
+               Add_Result (Res, R);
+               Used := True;
+            end if;
+         end if;
+         if not Used then
+            Sem_Name_Free_Result (Sub_Name, Null_Iir);
+         end if;
+      end Sem_Parenthesis_Function;
+
       Actual : Iir;
       Actual_Expr : Iir;
    begin
@@ -1945,38 +1977,13 @@ package body Sem_Names is
             when Iir_Kind_Overload_List =>
                declare
                   El : Iir;
-                  Used : Boolean;
-                  R : Iir;
-                  Match : Boolean;
                   Prefix_List : Iir_List;
                begin
                   Prefix_List := Get_Overload_List (Prefix);
                   for I in Natural loop
                      El := Get_Nth_Element (Prefix_List, I);
                      exit when El = Null_Iir;
-                     Used := False;
-                     if Get_Kind (El) in Iir_Kinds_Function_Declaration then
-                        Sem_Association_Chain
-                          (Get_Interface_Declaration_Chain (El),
-                           Assoc_Chain, False, Missing_Parameter, Name, Match);
-                        if Match then
-                           Add_Result
-                             (Res, Sem_As_Function_Call (Prefix_Name, El,
-                                                         Assoc_Chain));
-                           Used := True;
-                        end if;
-                     end if;
-                     if Get_Kind (El) not in Iir_Kinds_Procedure_Declaration
-                     then
-                        R := Sem_As_Indexed_Or_Slice_Name (El, False);
-                        if R /= Null_Iir then
-                           Add_Result (Res, R);
-                           Used := True;
-                        end if;
-                     end if;
-                     if not Used then
-                        Sem_Name_Free_Result (El, Null_Iir);
-                     end if;
+                     Sem_Parenthesis_Function (El);
                   end loop;
                end;
                if Res = Null_Iir then
@@ -1985,9 +1992,7 @@ package body Sem_Names is
                        & Disp_Node (Prefix_Name), Name);
                end if;
             when Iir_Kinds_Function_Declaration =>
-               Add_Result (Res, Sem_As_Function_Call (Prefix_Name,
-                                                      Prefix, Assoc_Chain));
-               Add_Result (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, False));
+               Sem_Parenthesis_Function (Prefix);
                if Res = Null_Iir then
                   Error_Msg_Sem
                     ("prefix is neither a function name "
diff --git a/testsuite/gna/bug7186/bug.vhdl b/testsuite/gna/bug7186/bug.vhdl
new file mode 100644
index 000000000..958752142
--- /dev/null
+++ b/testsuite/gna/bug7186/bug.vhdl
@@ -0,0 +1,24 @@
+library IEEE;
+use ieee.numeric_std.all;
+use ieee.std_logic_1164.all;
+
+-- A testbench has no ports.
+entity system is
+end system;
+
+architecture behav of system is
+  subtype entry is unsigned(7 downto 0);
+  type invect is array (natural range <>) of entry;
+  signal minimum : entry;
+  signal vec : invect(0 to 20);
+  function min(iv : invect) return entry is
+  begin
+    return iv(0);
+  end;
+begin
+  process
+  begin
+    minimum <= min(invect); -- should be vec not invect
+    wait;
+  end process;
+end behav;
diff --git a/testsuite/gna/bug7186/testsuite.sh b/testsuite/gna/bug7186/testsuite.sh
new file mode 100755
index 000000000..fada7027b
--- /dev/null
+++ b/testsuite/gna/bug7186/testsuite.sh
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+. ../../testenv.sh
+
+analyze_failure bug.vhdl
+
+clean
+
+echo "Test successful"
-- 
cgit v1.2.3