diff mbox

[Ada] PR ada/47818 - Pragma Assert rejected with No_Implementation_Pragmas restriction

Message ID 20110505194543.GA1329@localhost.localdomain
State New
Headers show

Commit Message

Eugeniy Meshcheryakov May 5, 2011, 7:45 p.m. UTC
Hello,

Compilation of code containing pragma Assert fails if restriction
No_Implementation_Pragmas is used, even with -gnat2005 or -gnat2012
flags:

% cat test.adb
pragma Restrictions(No_Implementation_Pragmas);

procedure test(I : Integer) is
begin
  pragma Assert(I /= 1);
  null;
end;
% gcc -c test.adb -gnat2005
test.adb:5:03: violation of restriction "no_implementation_pragmas" at line 1

Source file gcc/ada/sem_prag.adb contains correct check for Pragma_Assert
(Ada_2005_Pragma). But this pragma is then rewritten as pragma Check and
restrictions (GNAT_Pragma) are tested again. This test fails and causes
compilation error.

The patch was tested on x86_64, applied to trunk.

Regards,
Eugeniy Meshcheryakov

2011-05-05  Eugeniy Meshcheryakov <eugen@debian.org>

	PR ada/47818
	* sem_prag.adb (Pragma_Check): Don't check restrictions on rewritten
	  pragma Assert.
	
2011-05-05  Eugeniy Meshcheryakov <eugen@debian.org>

	PR ada/47818
	* gnat.dg/pragma_assert.adb: New.
diff mbox

Patch

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index fd509c4..b5bae50 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -6477,7 +6477,16 @@  package body Sem_Prag is
             --  Set True if category of assertions referenced by Name enabled
 
          begin
-            GNAT_Pragma;
+            --  This could be a rewritten pragma Assert. If it is the case
+            --  then don't check restrictions, because they are different for
+            --  pragma Assert and were already checked.
+
+            if Nkind (Original_Node (N)) /= N_Pragma
+              or else Pragma_Name (Original_Node (N)) /= Name_Assert
+            then
+               GNAT_Pragma;
+            end if;
+
             Check_At_Least_N_Arguments (2);
             Check_At_Most_N_Arguments (3);
             Check_Optional_Identifier (Arg1, Name_Name);
diff --git a/gcc/testsuite/gnat.dg/pragma_assert.adb b/gcc/testsuite/gnat.dg/pragma_assert.adb
new file mode 100644
index 0000000..4bda0a0
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/pragma_assert.adb
@@ -0,0 +1,10 @@ 
+-- {dg-do compile}
+-- {dg-options -gnat05}
+pragma Restrictions (No_Implementation_Pragmas);
+
+procedure Pragma_Assert is
+   X : Integer;
+begin
+   X := 1;
+   pragma Assert (X = 1);
+end Pragma_Assert;