This reimplements the No_Strict_Aliasing configuration pragma, which didn't
work neither for private types nor for access-to-unconstrained-array types.

The following program must compile quietly with -O2:

pragma No_Strict_Aliasing;
with Q; use Q;

package P is

   type Ptr is private;

   type Arr is array (Natural range <>) of Integer;

   type Array_Ptr is access all Arr;

   procedure Dummy;

private

   type Rec is record
      Data : Integer;
   end record;

   type Ptr is access Rec;

end P;
with Ada.Unchecked_Conversion;

package body P is

   function Any_Ptr_To_Map_Ptr is
      new Ada.Unchecked_Conversion (Q.T_ANY_PTR, Ptr);

   function Any_Array_Ptr_To_Map_Ptr is
      new Ada.Unchecked_Conversion (Q.T_ANY_ARRAY_PTR, Array_Ptr);

   procedure Dummy is begin null; end;

end P;
package Q is

   type T_BYTE is new INTEGER range 0 .. 255;
   for T_BYTE'size use 8;

   type T_ANY_PTR is access T_BYTE;

   type T_BYTE_ARRAY is array (Natural range <>) of T_BYTE;

   type T_ANY_ARRAY_PTR is access T_BYTE_ARRAY;

end Q;

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

2015-01-07  Eric Botcazou  <ebotca...@adacore.com>

        * sem_ch3.adb (Analyze_Full_Type_Declaration): Do not
        automatically set No_Strict_Aliasing on access types.
        * fe.h (No_Strict_Aliasing_CP): Declare.
        * gcc-interface/trans.c (gigi): Force flag_strict_aliasing to 0 if
        No_Strict_Aliasing_CP is set.

Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb (revision 219285)
+++ sem_ch3.adb (working copy)
@@ -2657,12 +2657,6 @@
                   Add_RACW_Features (Def_Id);
                end if;
 
-               --  Set no strict aliasing flag if config pragma seen
-
-               if Opt.No_Strict_Aliasing then
-                  Set_No_Strict_Aliasing (Base_Type (Def_Id));
-               end if;
-
             when N_Array_Type_Definition =>
                Array_Type_Declaration (T, Def);
 
Index: fe.h
===================================================================
--- fe.h        (revision 219191)
+++ fe.h        (working copy)
@@ -176,6 +176,7 @@
 #define Generate_SCO_Instance_Table    opt__generate_sco_instance_table
 #define GNAT_Mode                      opt__gnat_mode
 #define List_Representation_Info       opt__list_representation_info
+#define No_Strict_Aliasing_CP          opt__no_strict_aliasing
 
 typedef enum {Setjmp_Longjmp, Back_End_Exceptions} Exception_Mechanism_Type;
 
@@ -187,6 +188,7 @@
 extern Boolean Generate_SCO_Instance_Table;
 extern Boolean GNAT_Mode;
 extern Int List_Representation_Info;
+extern Boolean No_Strict_Aliasing_CP;
 
 /* restrict: */
 
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c       (revision 219286)
+++ gcc-interface/trans.c       (working copy)
@@ -667,6 +667,10 @@
   /* Initialize the GCC support for FP operations.  */
   gnat_init_gcc_fp ();
 
+  /* Force -fno-strict-aliasing if the configuration pragma was seen.  */
+  if (No_Strict_Aliasing_CP)
+    flag_strict_aliasing = 0;
+
   /* Now translate the compilation unit proper.  */
   Compilation_Unit_to_gnu (gnat_root);
 

Reply via email to