[Ada] Bad warning: Size in Compile_Time_Error in nested instance

Message ID 20191216103826.GA39366@adacore.com
State New
Headers show
Series
  • [Ada] Bad warning: Size in Compile_Time_Error in nested instance
Related show

Commit Message

Pierre-Marie de Rodat Dec. 16, 2019, 10:38 a.m.
This patch fixes a bug in which if a Size attribute occurs in a pragma
Compile_Time_Error, and the pragma occurs in a generic unit that is
instantiated in another generic unit, and that other generic unit is
instantiated, then the compiler does not know the value of Size at
compile time. It issues a warning in the nested instance:

    warning: in instantiation at ...
    warning: in instantiation at ...
    warning: condition is not known at compile time

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-12-16  Bob Duff  <duff@adacore.com>

gcc/ada/

	* sem_attr.adb (Analyze_Attribute): Use Known_RM_Size. But we
	still need Size_Known_At_Compile_Time, because when the size
	really is known, sometimes only one or the other of these is
	True.

Patch

--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -5841,13 +5841,16 @@  package body Sem_Attr is
          --  Time_Errors after the back end has been called and this occurrence
          --  of 'Size is known at compile time then it is safe to perform this
          --  evaluation. Needed to perform the static evaluation of the full
-         --  boolean expression of these pragmas.
+         --  boolean expression of these pragmas. Note that Known_RM_Size is
+         --  sometimes True when Size_Known_At_Compile_Time is False, when the
+         --  back end has computed it.
 
          if In_Compile_Time_Warning_Or_Error
            and then Is_Entity_Name (P)
            and then (Is_Type (Entity (P))
                       or else Ekind (Entity (P)) = E_Enumeration_Literal)
-           and then Size_Known_At_Compile_Time (Entity (P))
+           and then (Known_RM_Size (Entity (P))
+                       or else Size_Known_At_Compile_Time (Entity (P)))
          then
             declare
                Siz : Uint;