diff mbox series

[Ada] Spurious error on System'To_Address in -gnatc mode

Message ID 20171116125356.GA103165@adacore.com
State New
Headers show
Series [Ada] Spurious error on System'To_Address in -gnatc mode | expand

Commit Message

Pierre-Marie de Rodat Nov. 16, 2017, 12:53 p.m. UTC
This patch fixes a bug where if an address clause specifies a call to
System'To_Address as the address, and the code is compiled with the
-gnatc switch, the compiler gives a spurious error message.

The following test should compile quietly with -gnatc:

gcc -c -gnatc counter.ads

with System;

package Counter is
   type Bar is
      record
	 X : Integer;
	 Y : Integer;
      end record;

   Null_Bar : constant Bar := (0, 0);

   Address : constant := 16#D000_0000#;

   Foo : Bar := Null_Bar;
   for Foo'Address use System'To_Address (Address);
end Counter;

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

2017-11-16  Bob Duff  <duff@adacore.com>

	* sem_ch13.adb (Check_Expr_Constants): Avoid error message in case of
	System'To_Address.
diff mbox series

Patch

Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb	(revision 254797)
+++ sem_ch13.adb	(working copy)
@@ -9783,6 +9783,15 @@ 
                then
                   Check_At_Constant_Address (Prefix (Nod));
 
+               --  Normally, System'To_Address will have been transformed into
+               --  an Unchecked_Conversion, but in -gnatc mode, it will not,
+               --  and we don't want to give an error, because the whole point
+               --  of 'To_Address is that it is static.
+
+               elsif Attribute_Name (Nod) = Name_To_Address then
+                  pragma Assert (Operating_Mode = Check_Semantics);
+                  null;
+
                else
                   Check_Expr_Constants (Prefix (Nod));
                   Check_List_Constants (Expressions (Nod));