OSDN Git Service

2007-04-20 Eric Botcazou <ebotcazou@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / exp_prag.adb
index 54ea041..710ff7d 100644 (file)
@@ -6,9 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                            $Revision$
---                                                                          --
---          Copyright (C) 1992-2002 Free Software Foundation, Inc.          --
+--          Copyright (C) 1992-2007, 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- --
 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
 -- for  more details.  You should have  received  a copy of the GNU General --
 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
 with Atree;    use Atree;
 with Casing;   use Casing;
+with Debug;    use Debug;
 with Einfo;    use Einfo;
 with Errout;   use Errout;
 with Exp_Ch11; use Exp_Ch11;
@@ -38,6 +37,8 @@ with Namet;    use Namet;
 with Nlists;   use Nlists;
 with Nmake;    use Nmake;
 with Opt;      use Opt;
+with Restrict; use Restrict;
+with Rident;   use Rident;
 with Rtsfind;  use Rtsfind;
 with Sem;      use Sem;
 with Sem_Eval; use Sem_Eval;
@@ -48,6 +49,7 @@ with Sinput;   use Sinput;
 with Snames;   use Snames;
 with Stringt;  use Stringt;
 with Stand;    use Stand;
+with Targparm; use Targparm;
 with Tbuild;   use Tbuild;
 with Uintp;    use Uintp;
 
@@ -59,22 +61,31 @@ package body Exp_Prag is
 
    function Arg1 (N : Node_Id) return Node_Id;
    function Arg2 (N : Node_Id) return Node_Id;
-   --  Obtain specified Pragma_Argument_Association
+   --  Obtain specified pragma argument expression
 
    procedure Expand_Pragma_Abort_Defer             (N : Node_Id);
    procedure Expand_Pragma_Assert                  (N : Node_Id);
-   procedure Expand_Pragma_Import                  (N : Node_Id);
+   procedure Expand_Pragma_Common_Object           (N : Node_Id);
+   procedure Expand_Pragma_Import_Or_Interface     (N : Node_Id);
    procedure Expand_Pragma_Import_Export_Exception (N : Node_Id);
    procedure Expand_Pragma_Inspection_Point        (N : Node_Id);
    procedure Expand_Pragma_Interrupt_Priority      (N : Node_Id);
+   procedure Expand_Pragma_Psect_Object            (N : Node_Id);
 
    ----------
    -- Arg1 --
    ----------
 
    function Arg1 (N : Node_Id) return Node_Id is
+      Arg : constant Node_Id := First (Pragma_Argument_Associations (N));
    begin
-      return First (Pragma_Argument_Associations (N));
+      if Present (Arg)
+        and then Nkind (Arg) = N_Pragma_Argument_Association
+      then
+         return Expression (Arg);
+      else
+         return Arg;
+      end if;
    end Arg1;
 
    ----------
@@ -82,8 +93,23 @@ package body Exp_Prag is
    ----------
 
    function Arg2 (N : Node_Id) return Node_Id is
+      Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
    begin
-      return Next (Arg1 (N));
+      if No (Arg1) then
+         return Empty;
+      else
+         declare
+            Arg : constant Node_Id := Next (Arg1);
+         begin
+            if Present (Arg)
+              and then Nkind (Arg) = N_Pragma_Argument_Association
+            then
+               return Expression (Arg);
+            else
+               return Arg;
+            end if;
+         end;
+      end if;
    end Arg2;
 
    ---------------------
@@ -106,11 +132,14 @@ package body Exp_Prag is
             when Pragma_Assert =>
                Expand_Pragma_Assert (N);
 
+            when Pragma_Common_Object =>
+               Expand_Pragma_Common_Object (N);
+
             when Pragma_Export_Exception =>
                Expand_Pragma_Import_Export_Exception (N);
 
             when Pragma_Import =>
-               Expand_Pragma_Import (N);
+               Expand_Pragma_Import_Or_Interface (N);
 
             when Pragma_Import_Exception =>
                Expand_Pragma_Import_Export_Exception (N);
@@ -118,9 +147,15 @@ package body Exp_Prag is
             when Pragma_Inspection_Point =>
                Expand_Pragma_Inspection_Point (N);
 
+            when Pragma_Interface =>
+               Expand_Pragma_Import_Or_Interface (N);
+
             when Pragma_Interrupt_Priority =>
                Expand_Pragma_Interrupt_Priority (N);
 
+            when Pragma_Psect_Object =>
+               Expand_Pragma_Psect_Object (N);
+
             --  All other pragmas need no expander action
 
             when others => null;
@@ -196,7 +231,7 @@ package body Exp_Prag is
 
    procedure Expand_Pragma_Assert (N : Node_Id) is
       Loc  : constant Source_Ptr := Sloc (N);
-      Cond : constant Node_Id    := Expression (Arg1 (N));
+      Cond : constant Node_Id    := Arg1 (N);
       Msg  : String_Id;
 
    begin
@@ -207,7 +242,7 @@ package body Exp_Prag is
 
       --  Since assertions are on, we rewrite the pragma with its
       --  corresponding if statement, and then analyze the statement
-      --  The expansion transforms:
+      --  The normal case expansion transforms:
 
       --    pragma Assert (condition [,message]);
 
@@ -220,30 +255,70 @@ package body Exp_Prag is
       --  where Str is the message if one is present, or the default of
       --  file:line if no message is given.
 
-      --  First, we need to prepare the character literal
+      --  An alternative expansion is used when the No_Exception_Propagation
+      --  restriction is active and there is a local Assert_Failure handler.
+      --  This is not a common combination of circumstances, but it occurs in
+      --  the context of Aunit and the zero footprint profile. In this case we
+      --  generate:
 
-      if Present (Arg2 (N)) then
-         Msg := Strval (Expr_Value_S (Expression (Arg2 (N))));
-      else
-         Build_Location_String (Loc);
-         Msg := String_From_Name_Buffer;
-      end if;
+      --    if not condition then
+      --       raise Assert_Failure;
+      --    end if;
+
+      --  This will then be transformed into a goto, and the local handler will
+      --  be able to handle the assert error (which would not be the case if a
+      --  call is made to the Raise_Assert_Failure procedure).
+
+      --  Note that the reason we do not always generate a direct raise is that
+      --  the form in which the procedure is called allows for more efficient
+      --  breakpointing of assertion errors.
 
-      --  Now generate the if statement. Note that we consider this to be
-      --  an explicit conditional in the source, not an implicit if, so we
+      --  Generate the appropriate if statement. Note that we consider this to
+      --  be an explicit conditional in the source, not an implicit if, so we
       --  do not call Make_Implicit_If_Statement.
 
-      Rewrite (N,
-        Make_If_Statement (Loc,
-          Condition =>
-            Make_Op_Not (Loc,
-              Right_Opnd => Cond),
-          Then_Statements => New_List (
-            Make_Procedure_Call_Statement (Loc,
-              Name =>
-                New_Reference_To (RTE (RE_Raise_Assert_Failure), Loc),
-              Parameter_Associations => New_List (
-                Make_String_Literal (Loc, Msg))))));
+      --  Case where we generate a direct raise
+
+      if (Debug_Flag_Dot_G
+          or else Restriction_Active (No_Exception_Propagation))
+        and then Present (Find_Local_Handler (RTE (RE_Assert_Failure), N))
+      then
+         Rewrite (N,
+           Make_If_Statement (Loc,
+             Condition =>
+               Make_Op_Not (Loc,
+                 Right_Opnd => Cond),
+             Then_Statements => New_List (
+               Make_Raise_Statement (Loc,
+                 Name =>
+                   New_Reference_To (RTE (RE_Assert_Failure), Loc)))));
+
+      --  Case where we call the procedure
+
+      else
+         --  First, we need to prepare the string literal
+
+         if Present (Arg2 (N)) then
+            Msg := Strval (Expr_Value_S (Arg2 (N)));
+         else
+            Build_Location_String (Loc);
+            Msg := String_From_Name_Buffer;
+         end if;
+
+         --  Now rewrite as an if statement
+
+         Rewrite (N,
+           Make_If_Statement (Loc,
+             Condition =>
+               Make_Op_Not (Loc,
+                 Right_Opnd => Cond),
+             Then_Statements => New_List (
+               Make_Procedure_Call_Statement (Loc,
+                 Name =>
+                   New_Reference_To (RTE (RE_Raise_Assert_Failure), Loc),
+                 Parameter_Associations => New_List (
+                   Make_String_Literal (Loc, Msg))))));
+      end if;
 
       Analyze (N);
 
@@ -252,9 +327,8 @@ package body Exp_Prag is
       if Nkind (N) = N_Procedure_Call_Statement
         and then Is_RTE (Entity (Name (N)), RE_Raise_Assert_Failure)
       then
-         --  If original condition was a Standard.False, we assume
-         --  that this is indeed intented to raise assert error
-         --  and no warning is required.
+         --  If original condition was a Standard.False, we assume that this is
+         --  indeed intented to raise assert error and no warning is required.
 
          if Is_Entity_Name (Original_Node (Cond))
            and then Entity (Original_Node (Cond)) = Standard_False
@@ -266,41 +340,127 @@ package body Exp_Prag is
       end if;
    end Expand_Pragma_Assert;
 
-   --------------------------
-   -- Expand_Pragma_Import --
-   --------------------------
+   ---------------------------------
+   -- Expand_Pragma_Common_Object --
+   ---------------------------------
+
+   --  Use a machine attribute to replicate semantic effect in DEC Ada
+
+   --    pragma Machine_Attribute (intern_name, "common_object", extern_name);
+
+   --  For now we do nothing with the size attribute ???
+
+   procedure Expand_Pragma_Common_Object (N : Node_Id) is
+      Loc : constant Source_Ptr := Sloc (N);
+
+      Internal : constant Node_Id := Arg1 (N);
+      External : constant Node_Id := Arg2 (N);
+
+      Psect : Node_Id;
+      --  Psect value upper cased as string literal
+
+      Iloc : constant Source_Ptr := Sloc (Internal);
+      Eloc : constant Source_Ptr := Sloc (External);
+      Ploc : Source_Ptr;
+
+   begin
+      --  Acquire Psect value and fold to upper case
+
+      if Present (External) then
+         if Nkind (External) = N_String_Literal then
+            String_To_Name_Buffer (Strval (External));
+         else
+            Get_Name_String (Chars (External));
+         end if;
+
+         Set_All_Upper_Case;
+
+         Psect :=
+           Make_String_Literal (Eloc,
+             Strval => String_From_Name_Buffer);
+
+      else
+         Get_Name_String (Chars (Internal));
+         Set_All_Upper_Case;
+         Psect :=
+           Make_String_Literal (Iloc,
+             Strval => String_From_Name_Buffer);
+      end if;
+
+      Ploc := Sloc (Psect);
+
+      --  Insert the pragma
+
+      Insert_After_And_Analyze (N,
+
+         Make_Pragma (Loc,
+           Chars => Name_Machine_Attribute,
+           Pragma_Argument_Associations => New_List (
+             Make_Pragma_Argument_Association (Iloc,
+               Expression => New_Copy_Tree (Internal)),
+             Make_Pragma_Argument_Association (Eloc,
+               Expression =>
+                 Make_String_Literal (Sloc => Ploc,
+                   Strval => "common_object")),
+             Make_Pragma_Argument_Association (Ploc,
+               Expression => New_Copy_Tree (Psect)))));
+
+   end Expand_Pragma_Common_Object;
+
+   ---------------------------------------
+   -- Expand_Pragma_Import_Or_Interface --
+   ---------------------------------------
 
    --  When applied to a variable, the default initialization must not be
    --  done. As it is already done when the pragma is found, we just get rid
    --  of the call the initialization procedure which followed the object
-   --  declaration.
+   --  declaration. The call is inserted after the declaration, but validity
+   --  checks may also have been inserted and the initialization call does
+   --  not necessarily appear immediately after the object declaration.
 
    --  We can't use the freezing mechanism for this purpose, since we
    --  have to elaborate the initialization expression when it is first
    --  seen (i.e. this elaboration cannot be deferred to the freeze point).
 
-   procedure Expand_Pragma_Import (N : Node_Id) is
-      Def_Id    : constant Entity_Id := Entity (Expression (Arg2 (N)));
+   procedure Expand_Pragma_Import_Or_Interface (N : Node_Id) is
+      Def_Id    : constant Entity_Id := Entity (Arg2 (N));
       Typ       : Entity_Id;
-      After_Def : Node_Id;
+      Init_Call : Node_Id;
 
    begin
       if Ekind (Def_Id) = E_Variable then
          Typ  := Etype (Def_Id);
-         After_Def := Next (Parent (Def_Id));
 
-         if Has_Non_Null_Base_Init_Proc (Typ)
-           and then Nkind (After_Def) = N_Procedure_Call_Statement
-           and then Is_Entity_Name (Name (After_Def))
-           and then Entity (Name (After_Def)) = Base_Init_Proc (Typ)
-         then
-            Remove (After_Def);
+         --  Iterate from declaration of object to import pragma, to find
+         --  generated initialization call for object, if any.
+
+         Init_Call := Next (Parent (Def_Id));
+         while Present (Init_Call) and then Init_Call /= N loop
+            if Has_Non_Null_Base_Init_Proc (Typ)
+              and then Nkind (Init_Call) = N_Procedure_Call_Statement
+              and then Is_Entity_Name (Name (Init_Call))
+              and then Entity (Name (Init_Call)) = Base_Init_Proc (Typ)
+            then
+               Remove (Init_Call);
+               exit;
+            else
+               Next (Init_Call);
+            end if;
+         end loop;
 
-         elsif Is_Access_Type (Typ) then
+         --  Any default initialization expression should be removed
+         --  (e.g., null defaults for access objects, zero initialization
+         --  of packed bit arrays). Imported objects aren't allowed to
+         --  have explicit initialization, so the expression must have
+         --  been generated by the compiler.
+
+         if Init_Call = N
+           and then Present (Expression (Parent (Def_Id)))
+         then
             Set_Expression (Parent (Def_Id), Empty);
          end if;
       end if;
-   end Expand_Pragma_Import;
+   end Expand_Pragma_Import_Or_Interface;
 
    -------------------------------------------
    -- Expand_Pragma_Import_Export_Exception --
@@ -314,145 +474,176 @@ package body Exp_Prag is
    --  with the unexpanded name of the exception (if not already set).
 
    procedure Expand_Pragma_Import_Export_Exception (N : Node_Id) is
-      Id     : constant Entity_Id := Entity (Expression (Arg1 (N)));
-      Call   : constant Node_Id := Register_Exception_Call (Id);
-      Loc    : constant Source_Ptr := Sloc (N);
    begin
-      if Present (Call) then
-         declare
-            Excep_Internal : constant Node_Id :=
-                              Make_Defining_Identifier
-                               (Loc, New_Internal_Name ('V'));
-            Export_Pragma  : Node_Id;
-            Excep_Alias    : Node_Id;
-            Excep_Object   : Node_Id;
-            Excep_Image : String_Id;
-            Exdata      : List_Id;
-            Lang1       : Node_Id;
-            Lang2       : Node_Id;
-            Lang3       : Node_Id;
-            Code        : Node_Id;
-         begin
-            if Present (Interface_Name (Id)) then
-               Excep_Image := Strval (Interface_Name (Id));
-            else
-               Get_Name_String (Chars (Id));
-               Set_All_Upper_Case;
-               Excep_Image := String_From_Name_Buffer;
-            end if;
+      --  This pragma is only effective on OpenVMS systems, it was ignored
+      --  on non-VMS systems, and we need to ignore it here as well.
 
-            Exdata := Component_Associations (Expression (Parent (Id)));
-
-            if Is_VMS_Exception (Id) then
-
-               Lang1 := Next (First (Exdata));
-               Lang2 := Next (Lang1);
-               Lang3 := Next (Lang2);
-
-               Rewrite (Expression (Lang1),
-                 Make_Character_Literal (Loc, Name_uV, Get_Char_Code ('V')));
-               Analyze (Expression (Lang1));
-
-               Rewrite (Expression (Lang2),
-                 Make_Character_Literal (Loc, Name_uM, Get_Char_Code ('M')));
-               Analyze (Expression (Lang2));
-
-               Rewrite (Expression (Lang3),
-                 Make_Character_Literal (Loc, Name_uS, Get_Char_Code ('S')));
-               Analyze (Expression (Lang3));
-
-               if Exception_Code (Id) /= No_Uint then
-                  Code := Make_Integer_Literal (Loc, Exception_Code (Id));
-
-                  Excep_Object :=
-                    Make_Object_Declaration (Loc,
-                      Defining_Identifier => Excep_Internal,
-                      Object_Definition   =>
-                        New_Reference_To (Standard_Integer, Loc));
-
-                  Insert_Action (N, Excep_Object);
-                  Analyze (Excep_Object);
-
-                  Start_String;
-                  Store_String_Int (UI_To_Int (Exception_Code (Id)) / 8 * 8);
-
-                  Excep_Alias :=
-                    Make_Pragma
-                      (Loc,
-                       Name_Linker_Alias,
-                       New_List
-                         (Make_Pragma_Argument_Association
-                            (Sloc => Loc,
-                             Expression =>
-                               New_Reference_To (Excep_Internal, Loc)),
-                          Make_Pragma_Argument_Association
-                            (Sloc => Loc,
-                             Expression =>
-                               Make_String_Literal
-                                 (Sloc => Loc,
-                                  Strval => End_String))));
-
-                  Insert_Action (N, Excep_Alias);
-                  Analyze (Excep_Alias);
-
-                  Export_Pragma :=
-                    Make_Pragma
-                      (Loc,
-                       Name_Export,
-                       New_List
-                         (Make_Pragma_Argument_Association
-                            (Sloc => Loc,
-                             Expression => Make_Identifier (Loc, Name_C)),
-                          Make_Pragma_Argument_Association
-                            (Sloc => Loc,
-                             Expression =>
-                               New_Reference_To (Excep_Internal, Loc)),
-                          Make_Pragma_Argument_Association
-                            (Sloc => Loc,
-                             Expression =>
-                               Make_String_Literal
-                                 (Sloc => Loc,
-                                  Strval => Excep_Image)),
-                          Make_Pragma_Argument_Association
-                            (Sloc => Loc,
-                             Expression =>
-                               Make_String_Literal
-                                 (Sloc => Loc,
-                                  Strval => Excep_Image))));
-
-                  Insert_Action (N, Export_Pragma);
-                  Analyze (Export_Pragma);
+      if not OpenVMS_On_Target then
+         return;
+      end if;
 
+      declare
+         Id     : constant Entity_Id := Entity (Arg1 (N));
+         Call   : constant Node_Id := Register_Exception_Call (Id);
+         Loc    : constant Source_Ptr := Sloc (N);
+
+      begin
+         if Present (Call) then
+            declare
+               Excep_Internal : constant Node_Id :=
+                                 Make_Defining_Identifier
+                                  (Loc, New_Internal_Name ('V'));
+               Export_Pragma  : Node_Id;
+               Excep_Alias    : Node_Id;
+               Excep_Object   : Node_Id;
+               Excep_Image : String_Id;
+               Exdata      : List_Id;
+               Lang1       : Node_Id;
+               Lang2       : Node_Id;
+               Lang3       : Node_Id;
+               Code        : Node_Id;
+
+            begin
+               if Present (Interface_Name (Id)) then
+                  Excep_Image := Strval (Interface_Name (Id));
                else
-                  Code :=
-                     Unchecked_Convert_To (Standard_Integer,
-                       Make_Function_Call (Loc,
-                         Name =>
-                           New_Reference_To (RTE (RE_Import_Value), Loc),
-                         Parameter_Associations => New_List
-                           (Make_String_Literal (Loc,
-                             Strval => Excep_Image))));
+                  Get_Name_String (Chars (Id));
+                  Set_All_Upper_Case;
+                  Excep_Image := String_From_Name_Buffer;
                end if;
 
-               Rewrite (Call,
-                 Make_Procedure_Call_Statement (Loc,
-                   Name => New_Reference_To
-                             (RTE (RE_Register_VMS_Exception), Loc),
-                   Parameter_Associations => New_List (Code)));
-
-               Analyze_And_Resolve (Code, Standard_Integer);
-               Analyze (Call);
-
-            end if;
+               Exdata := Component_Associations (Expression (Parent (Id)));
+
+               if Is_VMS_Exception (Id) then
+                  Lang1 := Next (First (Exdata));
+                  Lang2 := Next (Lang1);
+                  Lang3 := Next (Lang2);
+
+                  Rewrite (Expression (Lang1),
+                    Make_Character_Literal (Loc,
+                      Chars => Name_uV,
+                      Char_Literal_Value =>
+                        UI_From_Int (Character'Pos ('V'))));
+                  Analyze (Expression (Lang1));
+
+                  Rewrite (Expression (Lang2),
+                    Make_Character_Literal (Loc,
+                      Chars => Name_uM,
+                      Char_Literal_Value =>
+                        UI_From_Int (Character'Pos ('M'))));
+                  Analyze (Expression (Lang2));
+
+                  Rewrite (Expression (Lang3),
+                    Make_Character_Literal (Loc,
+                      Chars => Name_uS,
+                      Char_Literal_Value =>
+                        UI_From_Int (Character'Pos ('S'))));
+                  Analyze (Expression (Lang3));
+
+                  if Exception_Code (Id) /= No_Uint then
+                     Code :=
+                       Make_Integer_Literal (Loc,
+                         Intval => Exception_Code (Id));
+
+                     Excep_Object :=
+                       Make_Object_Declaration (Loc,
+                         Defining_Identifier => Excep_Internal,
+                         Object_Definition   =>
+                           New_Reference_To (RTE (RE_Exception_Code), Loc));
+
+                     Insert_Action (N, Excep_Object);
+                     Analyze (Excep_Object);
+
+                     Start_String;
+                     Store_String_Int
+                       (UI_To_Int (Exception_Code (Id)) / 8 * 8);
+
+                     Excep_Alias :=
+                       Make_Pragma
+                         (Loc,
+                          Name_Linker_Alias,
+                          New_List
+                            (Make_Pragma_Argument_Association
+                               (Sloc => Loc,
+                                Expression =>
+                                  New_Reference_To (Excep_Internal, Loc)),
+
+                             Make_Pragma_Argument_Association
+                               (Sloc => Loc,
+                                Expression =>
+                                  Make_String_Literal
+                                    (Sloc => Loc,
+                                     Strval => End_String))));
+
+                     Insert_Action (N, Excep_Alias);
+                     Analyze (Excep_Alias);
+
+                     Export_Pragma :=
+                       Make_Pragma
+                         (Loc,
+                          Name_Export,
+                          New_List
+                            (Make_Pragma_Argument_Association
+                               (Sloc => Loc,
+                                Expression => Make_Identifier (Loc, Name_C)),
+
+                             Make_Pragma_Argument_Association
+                               (Sloc => Loc,
+                                Expression =>
+                                  New_Reference_To (Excep_Internal, Loc)),
+
+                             Make_Pragma_Argument_Association
+                               (Sloc => Loc,
+                                Expression =>
+                                  Make_String_Literal
+                                    (Sloc => Loc,
+                                     Strval => Excep_Image)),
+
+                             Make_Pragma_Argument_Association
+                               (Sloc => Loc,
+                                Expression =>
+                                  Make_String_Literal
+                                    (Sloc => Loc,
+                                     Strval => Excep_Image))));
+
+                     Insert_Action (N, Export_Pragma);
+                     Analyze (Export_Pragma);
+
+                  else
+                     Code :=
+                        Unchecked_Convert_To (RTE (RE_Exception_Code),
+                          Make_Function_Call (Loc,
+                            Name =>
+                              New_Reference_To (RTE (RE_Import_Value), Loc),
+                            Parameter_Associations => New_List
+                              (Make_String_Literal (Loc,
+                                Strval => Excep_Image))));
+                  end if;
+
+                  Rewrite (Call,
+                    Make_Procedure_Call_Statement (Loc,
+                      Name => New_Reference_To
+                                (RTE (RE_Register_VMS_Exception), Loc),
+                      Parameter_Associations => New_List (
+                        Code,
+                        Unchecked_Convert_To (RTE (RE_Exception_Data_Ptr),
+                          Make_Attribute_Reference (Loc,
+                            Prefix         => New_Occurrence_Of (Id, Loc),
+                            Attribute_Name => Name_Unrestricted_Access)))));
+
+                  Analyze_And_Resolve (Code, RTE (RE_Exception_Code));
+                  Analyze (Call);
+               end if;
 
-            if not Present (Interface_Name (Id)) then
-               Set_Interface_Name (Id,
-                  Make_String_Literal
-                    (Sloc => Loc,
-                     Strval => Excep_Image));
-            end if;
-         end;
-      end if;
+               if No (Interface_Name (Id)) then
+                  Set_Interface_Name (Id,
+                     Make_String_Literal
+                       (Sloc => Loc,
+                        Strval => Excep_Image));
+               end if;
+            end;
+         end if;
+      end;
    end Expand_Pragma_Import_Export_Exception;
 
    ------------------------------------
@@ -534,4 +725,16 @@ package body Exp_Prag is
       end if;
    end Expand_Pragma_Interrupt_Priority;
 
+   --------------------------------
+   -- Expand_Pragma_Psect_Object --
+   --------------------------------
+
+   --  Convert to Common_Object, and expand the resulting pragma
+
+   procedure Expand_Pragma_Psect_Object (N : Node_Id) is
+   begin
+      Set_Chars (N, Name_Common_Object);
+      Expand_Pragma_Common_Object (N);
+   end Expand_Pragma_Psect_Object;
+
 end Exp_Prag;