diff mbox

[Ada] Allow run-time to be compiled with Normalize_Scalars

Message ID 20110802143923.GA5771@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 2, 2011, 2:39 p.m. UTC
This patch allows the run-time to be compiled with normalize scalars.
More specifically, it fixes a warning about initialiation overlays
when Ada.Strings.Unbounded.Aux is compiled with this pragma. Note
that the previous fix to pragma Suppress_Initialization is required.

The following test should compile without generating warnings:

     1. pragma Warnings (Off);
     2. with Ada.Strings.Unbounded.Aux;
     3. pragma Warnings (On);
     4. package RunTimeNS is
     5. end;

when compiled in the presence of a gnat.adc file containing

pragma Normalize_Scalars

with the command

gnatmake -q runtimens -a -f

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

2011-08-02  Robert Dewar  <dewar@adacore.com>

	* a-stunau.ads: Add pragma Suppress_Initialization for Big_String
	* freeze.adb (Warn_Overlay): Don't warn if initialization suppressed
	* s-stalib.ads: Add pragma Suppress_Initialization for Big_String
diff mbox

Patch

Index: freeze.adb
===================================================================
--- freeze.adb	(revision 177161)
+++ freeze.adb	(working copy)
@@ -5874,15 +5874,16 @@ 
       --  tested for because predefined String types are initialized by inline
       --  code rather than by an init_proc). Note that we do not give the
       --  warning for Initialize_Scalars, since we suppressed initialization
-      --  in this case.
+      --  in this case. Also, do not warn if Suppress_Initialization is set.
 
       if Present (Expr)
         and then not Is_Imported (Ent)
+        and then not Initialization_Suppressed (Typ)
         and then (Has_Non_Null_Base_Init_Proc (Typ)
-                    or else Is_Access_Type (Typ)
-                    or else (Normalize_Scalars
-                              and then (Is_Scalar_Type (Typ)
-                                         or else Is_String_Type (Typ))))
+                   or else Is_Access_Type (Typ)
+                   or else (Normalize_Scalars
+                             and then (Is_Scalar_Type (Typ)
+                                        or else Is_String_Type (Typ))))
       then
          if Nkind (Expr) = N_Attribute_Reference
            and then Is_Entity_Name (Prefix (Expr))
Index: a-stunau.ads
===================================================================
--- a-stunau.ads	(revision 176998)
+++ a-stunau.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -38,7 +38,18 @@ 
    pragma Preelaborate;
 
    subtype Big_String is String (1 .. Positive'Last);
+   pragma Suppress_Initialization (Big_String);
+   --  Type used to obtain string access to given address. Initialization is
+   --  suppressed, since we never want to have variables of this type, and
+   --  we never want to attempt initialiazation of virtual variables of this
+   --  type (e.g. when pragma Normalize_Scalars is used).
+
    type Big_String_Access is access all Big_String;
+   for Big_String_Access'Storage_Size use 0;
+   --  We use this access type to pass a pointer to an area of storage to be
+   --  accessed as a string. Of course when this pointer is used, it is the
+   --  responsibility of the accessor to ensure proper bounds. The storage
+   --  size clause ensures we do not allocate variables of this type.
 
    procedure Get_String
      (U : Unbounded_String;
Index: s-stalib.ads
===================================================================
--- s-stalib.ads	(revision 176998)
+++ s-stalib.ads	(working copy)
@@ -57,9 +57,19 @@ 
    pragma Preelaborate_05;
    pragma Warnings (On);
 
-   type Big_String_Ptr is access all String (Positive);
+   subtype Big_String is String (1 .. Positive'Last);
+   pragma Suppress_Initialization (Big_String);
+   --  Type used to obtain string access to given address. Initialization is
+   --  suppressed, since we never want to have variables of this type, and
+   --  we never want to attempt initialiazation of virtual variables of this
+   --  type (e.g. when pragma Normalize_Scalars is used).
+
+   type Big_String_Ptr is access all Big_String;
    for Big_String_Ptr'Storage_Size use 0;
-   --  A non-fat pointer type for null terminated strings
+   --  We use this access type to pass a pointer to an area of storage to be
+   --  accessed as a string. Of course when this pointer is used, it is the
+   --  responsibility of the accessor to ensure proper bounds. The storage
+   --  size clause ensures we do not allocate variables of this type.
 
    function To_Ptr is
      new Ada.Unchecked_Conversion (System.Address, Big_String_Ptr);