* [Ada] T'Size in pragma Compile_Time_Error
@ 2019-10-10 15:30 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-10-10 15:30 UTC (permalink / raw)
To: gcc-patches; +Cc: Bob Duff
[-- Attachment #1: Type: text/plain, Size: 1267 bytes --]
If a pragma Compile_Time_Error contains T'Size, then T'Size can be
computed as 0 instead of the correct value, causing missing or extra
error messages. The same applies to pragma Compile_Time_Warning. This
patch fixes that bug.
Running these commands:
gcc -c -g -O0 -gnata fillers-neq_error.ads
gcc -c -g -O0 -gnata fillers-neq_error-main.adb
On the following sources:
package Fillers is
Filler_Bytes : constant Long_Long_Integer := 1024 / 8;
type Filler_Range is new Long_Long_Integer range 0 .. Filler_Bytes - 1;
type Integer_8 is mod 2**8 with Size => 8;
type Filler_Type is array (Filler_Range) of Integer_8
with Pack;
end Fillers;
package Fillers.Neq_Error is
pragma Compile_Time_Error
(Filler_Type'Size /= 1024, "Filler_Type'Size /= 1024");
end Fillers.Neq_Error;
with Text_IO; use Text_IO;
procedure Fillers.Neq_Error.Main is
X : constant Integer := Filler_Type'Size;
begin
Put_Line (X'Img);
end Fillers.Neq_Error.Main;
Should execute silently.
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-10-10 Bob Duff <duff@adacore.com>
gcc/ada/
* sem_prag.adb (Defer_Compile_Time_Warning_Error_To_BE): In
addition to saving the pragma for further processing, copy the
pragma into the main unit if necessary.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 738 bytes --]
--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -32197,6 +32197,15 @@ package body Sem_Prag is
(New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
Scope => Current_Scope,
Prag => N));
+
+ -- If the Boolean expression contains T'Size, and we're not in the main
+ -- unit being compiled, then we need to copy the pragma into the main
+ -- unit, because otherwise T'Size might never be computed, leaving it
+ -- as 0.
+
+ if not In_Extended_Main_Code_Unit (N) then
+ Insert_Library_Level_Action (New_Copy_Tree (N));
+ end if;
end Defer_Compile_Time_Warning_Error_To_BE;
------------------------------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-10 15:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 15:30 [Ada] T'Size in pragma Compile_Time_Error Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).