aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2019-07-08 08:13:00 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-08 08:13:00 +0000
commitb91cdf756caafddf48433e6f93c4cc0049d292f8 (patch)
tree3b83cfe63f86f4a4b388d04831e1813753ac8d8e
parentffec45e390555f4881c841271464a9c264adbbca (diff)
downloadgcc-b91cdf756caafddf48433e6f93c4cc0049d292f8.zip
gcc-b91cdf756caafddf48433e6f93c4cc0049d292f8.tar.gz
gcc-b91cdf756caafddf48433e6f93c4cc0049d292f8.tar.bz2
[Ada] Spurious error reported by pragma Compile_Time_Error
The compiler may trigger spurious errors on pragmas Compile_Time_Error and Compile_Time_Warning when their boolean expression computes the size of a type. After this patch the following test compiles fine. with Interfaces; use Interfaces; package Types is type Arr is array (1 .. 6) of Unsigned_8 with Size => 48, Alignment => 1; type Rec is record Comp_1 : Unsigned_32; Comp_2 : Unsigned_16; end record with Size => 48, Alignment => 1; end Types; with Types; use Types; package Main is pragma Compile_Time_Error (Arr'Size = 12, "ERROR: Arr'Size is 48, not 12"); pragma Compile_Time_Error (Arr'Size = 48, "OK: Arr"); pragma Compile_Time_Error (Arr'Size /= 48, "ERROR: Arr'Size is 48"); pragma Compile_Time_Error (Rec'Size = 34, "ERROR: Rec'Size is 48, not 34"); pragma Compile_Time_Error (Rec'Size = 48, "OK: Rec"); pragma Compile_Time_Error (Rec'Size /= 48, "ERROR: Rec'Size is 48"); end Main; Command: gcc -c main.ads Output: main.ads:7:07: OK: Arr main.ads:14:07: OK: Rec 2019-07-08 Javier Miranda <miranda@adacore.com> gcc/ada/ * sem_attr.adb (Analyze_Attribute [Attribute_Size]): For pragmas used to report user defined compile time warning or errors handle 'Size for types with known static RM size. From-SVN: r273200
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/sem_attr.adb15
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 528556a..9a86909 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-08 Javier Miranda <miranda@adacore.com>
+
+ * sem_attr.adb (Analyze_Attribute [Attribute_Size]): For pragmas
+ used to report user defined compile time warning or errors
+ handle 'Size for types with known static RM size.
+
2019-07-08 Justin Squirek <squirek@adacore.com>
* exp_imgv.adb (Build_Enumeration_Image_Tables): Default SSO for
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index a3f9ffd..4c6cba6 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -5848,8 +5848,19 @@ package body Sem_Attr is
or else Ekind (Entity (P)) = E_Enumeration_Literal)
and then Size_Known_At_Compile_Time (Entity (P))
then
- Rewrite (N, Make_Integer_Literal (Sloc (N), Esize (Entity (P))));
- Analyze (N);
+ declare
+ Siz : Uint;
+
+ begin
+ if Known_Static_RM_Size (Entity (P)) then
+ Siz := RM_Size (Entity (P));
+ else
+ Siz := Esize (Entity (P));
+ end if;
+
+ Rewrite (N, Make_Integer_Literal (Sloc (N), Siz));
+ Analyze (N);
+ end;
end if;
-----------