public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Spurious error on System'To_Address in -gnatc mode
@ 2017-11-16 13:20 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2017-11-16 13:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bob Duff

[-- Attachment #1: Type: text/plain, Size: 749 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 859 bytes --]

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));

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-11-16 12:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-16 13:20 [Ada] Spurious error on System'To_Address in -gnatc mode 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).