aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/vhdl-sem_decls.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-01-14 18:50:22 +0100
committerTristan Gingold <tgingold@free.fr>2023-01-15 09:47:13 +0100
commit5b59dda84a7eb8a48e94a75b9b3ad008514089ce (patch)
tree7d8bcf6addec0f6ebb6bb68b50650d03607128c8 /src/vhdl/vhdl-sem_decls.adb
parent1fe5958609b57e7d134e0cc75713c530339a86dd (diff)
downloadghdl-5b59dda84a7eb8a48e94a75b9b3ad008514089ce.tar.gz
ghdl-5b59dda84a7eb8a48e94a75b9b3ad008514089ce.tar.bz2
ghdl-5b59dda84a7eb8a48e94a75b9b3ad008514089ce.zip
vhdl: add a warning to detect use before elaboration
Diffstat (limited to 'src/vhdl/vhdl-sem_decls.adb')
-rw-r--r--src/vhdl/vhdl-sem_decls.adb18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/vhdl/vhdl-sem_decls.adb b/src/vhdl/vhdl-sem_decls.adb
index 974cc21d8..21c4d3542 100644
--- a/src/vhdl/vhdl-sem_decls.adb
+++ b/src/vhdl/vhdl-sem_decls.adb
@@ -203,6 +203,7 @@ package body Vhdl.Sem_Decls is
procedure Sem_Interface_Object_Declaration
(Inter, Last : Iir; Interface_Kind : Interface_Kind_Type)
is
+ Prev_Unelaborated_Use_Allowed : Boolean;
A_Type: Iir;
Default_Value: Iir;
begin
@@ -229,12 +230,20 @@ package body Vhdl.Sem_Decls is
Default_Value := Get_Default_Value (Inter);
if Default_Value /= Null_Iir and then not Is_Error (A_Type) then
+
Deferred_Constant_Allowed := True;
+ Prev_Unelaborated_Use_Allowed := Unelaborated_Use_Allowed;
+ if Interface_Kind in Parameter_Interface_List then
+ Unelaborated_Use_Allowed := True;
+ end if;
+
Default_Value := Sem_Expression_Wildcard
(Default_Value, A_Type, Is_Object_Fully_Constrained (Inter));
Default_Value :=
Eval_Expr_Check_If_Static (Default_Value, A_Type);
+
Deferred_Constant_Allowed := False;
+ Unelaborated_Use_Allowed := Prev_Unelaborated_Use_Allowed;
Check_Read (Default_Value);
end if;
end if;
@@ -1120,6 +1129,15 @@ package body Vhdl.Sem_Decls is
Error_Msg_Sem (+Decl, "variable type must not be of the "
& "protected type body");
end if;
+
+ -- Check elaboration.
+ if Is_Protected
+ and then not Get_Elaborated_Flag (Base_Type)
+ then
+ Warning_Msg_Sem
+ (Warnid_Elaboration, +Decl,
+ "declaration of a protected type before the body");
+ end if;
end;
end if;
Set_Expr_Staticness (Decl, None);