OSDN Git Service

2009-04-08 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
index 251805d..cee2069 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2009, 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- --
@@ -40,7 +40,6 @@ with Exp_Dist; use Exp_Dist;
 with Lib;      use Lib;
 with Lib.Writ; use Lib.Writ;
 with Lib.Xref; use Lib.Xref;
-with Namet;    use Namet;
 with Namet.Sp; use Namet.Sp;
 with Nlists;   use Nlists;
 with Nmake;    use Nmake;
@@ -50,8 +49,11 @@ with Restrict; use Restrict;
 with Rident;   use Rident;
 with Rtsfind;  use Rtsfind;
 with Sem;      use Sem;
+with Sem_Aux;  use Sem_Aux;
 with Sem_Ch3;  use Sem_Ch3;
+with Sem_Ch6;  use Sem_Ch6;
 with Sem_Ch8;  use Sem_Ch8;
+with Sem_Ch12; use Sem_Ch12;
 with Sem_Ch13; use Sem_Ch13;
 with Sem_Dist; use Sem_Dist;
 with Sem_Elim; use Sem_Elim;
@@ -173,6 +175,14 @@ package body Sem_Prag is
    --  (the original one, following the renaming chain) is returned.
    --  Otherwise the entity is returned unchanged. Should be in Einfo???
 
+   function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
+   --  All the routines that check pragma arguments take either a pragma
+   --  argument association (in which case the expression of the argument
+   --  association is checked), or the expression directly. The function
+   --  Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
+   --  is a pragma argument association node, then its expression is returned,
+   --  otherwise Arg is returned unchanged.
+
    procedure rv;
    --  This is a dummy function called by the processing for pragma Reviewable.
    --  It is there for assisting front end debugging. By placing a Reviewable
@@ -230,6 +240,41 @@ package body Sem_Prag is
       end if;
    end Adjust_External_Name_Case;
 
+   ------------------------------
+   -- Analyze_PPC_In_Decl_Part --
+   ------------------------------
+
+   procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
+      Arg1 : constant Node_Id :=
+               First (Pragma_Argument_Associations (N));
+      Arg2 : constant Node_Id := Next (Arg1);
+
+   begin
+      --  Install formals and push subprogram spec onto scope stack
+      --  so that we can see the formals from the pragma.
+
+      Install_Formals (S);
+      Push_Scope (S);
+
+      --  Preanalyze the boolean expression, we treat this as a
+      --  spec expression (i.e. similar to a default expression).
+
+      Preanalyze_Spec_Expression
+        (Get_Pragma_Arg (Arg1), Standard_Boolean);
+
+      --  If there is a message argument, analyze it the same way
+
+      if Present (Arg2) then
+         Preanalyze_Spec_Expression
+           (Get_Pragma_Arg (Arg2), Standard_String);
+      end if;
+
+      --  Remove the subprogram from the scope stack now that the
+      --  pre-analysis of the precondition/postcondition is done.
+
+      End_Scope;
+   end Analyze_PPC_In_Decl_Part;
+
    --------------------
    -- Analyze_Pragma --
    --------------------
@@ -312,6 +357,7 @@ package body Sem_Prag is
 
       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
+      procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
       --  Check the specified argument Arg to make sure that it is an
       --  identifier whose name matches either N1 or N2 (or N3 if present).
       --  If not then give error and raise Pragma_Exit.
@@ -364,7 +410,7 @@ package body Sem_Prag is
 
       procedure Check_In_Main_Program;
       --  Common checks for pragmas that appear within a main program
-      --  (Priority, Main_Storage, Time_Slice).
+      --  (Priority, Main_Storage, Time_Slice, Relative_Deadline).
 
       procedure Check_Interrupt_Or_Attach_Handler;
       --  Common processing for first argument of pragma Interrupt_Handler
@@ -397,6 +443,30 @@ package body Sem_Prag is
       --  In this version of the procedure, the identifier name is given as
       --  a string with lower case letters.
 
+      procedure Check_Precondition_Postcondition (In_Body : out Boolean);
+      --  Called to process a precondition or postcondition pragma. There are
+      --  three cases:
+      --
+      --    The pragma appears after a subprogram spec
+      --
+      --      If the corresponding check is not enabled, the pragma is analyzed
+      --      but otherwise ignored and control returns with In_Body set False.
+      --
+      --      If the check is enabled, then the first step is to analyze the
+      --      pragma, but this is skipped if the subprogram spec appears within
+      --      a package specification (because this is the case where we delay
+      --      analysis till the end of the spec). Then (whether or not it was
+      --      analyzed), the pragma is chained to the subprogram in question
+      --      (using Spec_PPC_List and Next_Pragma) and control returns to the
+      --      caller with In_Body set False.
+      --
+      --    The pragma appears at the start of subprogram body declarations
+      --
+      --      In this case an immediate return to the caller is made with
+      --      In_Body set True, and the pragma is NOT analyzed.
+      --
+      --    In all other cases, an error message for bad placement is given
+
       procedure Check_Static_Constraint (Constr : Node_Id);
       --  Constr is a constraint from an N_Subtype_Indication node from a
       --  component constraint in an Unchecked_Union type. This routine checks
@@ -452,6 +522,13 @@ package body Sem_Prag is
       --  reference the identifier. After placing the message, Pragma_Exit
       --  is raised.
 
+      procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
+      pragma No_Return (Error_Pragma_Ref);
+      --  Outputs error message for current pragma. The message may contain
+      --  a % that will be replaced with the pragma name. The parameter Ref
+      --  must be an entity whose name can be referenced by & and sloc by #.
+      --  After placing the message, Pragma_Exit is raised.
+
       function Find_Lib_Unit_Name return Entity_Id;
       --  Used for a library unit pragma to find the entity to which the
       --  library unit pragma applies, returns the entity found.
@@ -484,14 +561,6 @@ package body Sem_Prag is
       --  optional identifiers when it returns). An entry in Args is Empty
       --  on return if the corresponding argument is not present.
 
-      function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
-      --  All the routines that check pragma arguments take either a pragma
-      --  argument association (in which case the expression of the argument
-      --  association is checked), or the expression directly. The function
-      --  Get_Pragma_Arg is a utility used to deal with these two cases. If
-      --  Arg is a pragma argument association node, then its expression is
-      --  returned, otherwise Arg is returned unchanged.
-
       procedure GNAT_Pragma;
       --  Called for all GNAT defined pragmas to check the relevant restriction
       --  (No_Implementation_Pragmas).
@@ -503,7 +572,7 @@ package body Sem_Prag is
       --  Decls where Decls is the list of declarative items.
 
       function Is_Configuration_Pragma return Boolean;
-      --  Deterermines if the placement of the current pragma is appropriate
+      --  Determines if the placement of the current pragma is appropriate
       --  for a configuration pragma.
 
       function Is_In_Context_Clause return Boolean;
@@ -515,6 +584,7 @@ package body Sem_Prag is
       --  expression, returns True if so, False if non-static or not String.
 
       procedure Pragma_Misplaced;
+      pragma No_Return (Pragma_Misplaced);
       --  Issue fatal error message for misplaced pragma
 
       procedure Process_Atomic_Shared_Volatile;
@@ -526,7 +596,7 @@ package body Sem_Prag is
       --  Common processing for Compile_Time_Error and Compile_Time_Warning
 
       procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
-      --  Common procesing for Convention, Interface, Import and Export.
+      --  Common processing for Convention, Interface, Import and Export.
       --  Checks first two arguments of pragma, and sets the appropriate
       --  convention value in the specified entity or entities. On return
       --  C is the convention, E is the referenced entity.
@@ -545,7 +615,7 @@ package body Sem_Prag is
         (Arg_Internal : Node_Id;
          Arg_External : Node_Id;
          Arg_Size     : Node_Id);
-      --  Common processing for the pragmass Import/Export_Object.
+      --  Common processing for the pragmas Import/Export_Object.
       --  The three arguments correspond to the three named parameters
       --  of the pragmas. An argument is empty if the corresponding
       --  parameter is not present in the pragma.
@@ -568,7 +638,7 @@ package body Sem_Prag is
          Arg_First_Optional_Parameter : Node_Id := Empty);
       --  Common processing for all extended Import and Export pragmas
       --  applying to subprograms. The caller omits any arguments that do
-      --  bnot apply to the pragma in question (for example, Arg_Result_Type
+      --  not apply to the pragma in question (for example, Arg_Result_Type
       --  can be non-Empty only in the Import_Function and Export_Function
       --  cases). The argument names correspond to the allowed pragma
       --  association identifiers.
@@ -603,7 +673,9 @@ package body Sem_Prag is
 
       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
       --  Common processing for Restrictions and Restriction_Warnings pragmas.
-      --  Warn is False for Restrictions, True for Restriction_Warnings.
+      --  Warn is True for Restriction_Warnings, or for Restrictions if the
+      --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
+      --  is not set in the Restrictions case.
 
       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
       --  Common processing for Suppress and Unsuppress. The boolean parameter
@@ -856,6 +928,24 @@ package body Sem_Prag is
          end if;
       end Check_Arg_Is_One_Of;
 
+      procedure Check_Arg_Is_One_Of
+        (Arg            : Node_Id;
+         N1, N2, N3, N4 : Name_Id)
+      is
+         Argx : constant Node_Id := Get_Pragma_Arg (Arg);
+
+      begin
+         Check_Arg_Is_Identifier (Argx);
+
+         if Chars (Argx) /= N1
+           and then Chars (Argx) /= N2
+           and then Chars (Argx) /= N3
+           and then Chars (Argx) /= N4
+         then
+            Error_Pragma_Arg ("invalid argument for pragma%", Argx);
+         end if;
+      end Check_Arg_Is_One_Of;
+
       ---------------------------------
       -- Check_Arg_Is_Queuing_Policy --
       ---------------------------------
@@ -1191,10 +1281,10 @@ package body Sem_Prag is
             --  sequence, so the only way we get here is by being in the
             --  declarative part of the body.
 
-            elsif Nkind (P) = N_Subprogram_Body
-              or else Nkind (P) = N_Package_Body
-              or else Nkind (P) = N_Task_Body
-              or else Nkind (P) = N_Entry_Body
+            elsif Nkind_In (P, N_Subprogram_Body,
+                               N_Package_Body,
+                               N_Task_Body,
+                               N_Entry_Body)
             then
                return;
             end if;
@@ -1256,6 +1346,143 @@ package body Sem_Prag is
          Check_Optional_Identifier (Arg, Name_Find);
       end Check_Optional_Identifier;
 
+      --------------------------------------
+      -- Check_Precondition_Postcondition --
+      --------------------------------------
+
+      procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
+         P  : Node_Id;
+         PO : Node_Id;
+
+         procedure Chain_PPC (PO : Node_Id);
+         --  If PO is a subprogram declaration node (or a generic subprogram
+         --  declaration node), then the precondition/postcondition applies
+         --  to this subprogram and the processing for the pragma is completed.
+         --  Otherwise the pragma is misplaced.
+
+         ---------------
+         -- Chain_PPC --
+         ---------------
+
+         procedure Chain_PPC (PO : Node_Id) is
+            S : Node_Id;
+
+         begin
+            if not Nkind_In (PO, N_Subprogram_Declaration,
+                                 N_Generic_Subprogram_Declaration)
+            then
+               Pragma_Misplaced;
+            end if;
+
+            --  Here if we have subprogram or generic subprogram declaration
+
+            S := Defining_Unit_Name (Specification (PO));
+
+            --  Analyze the pragma unless it appears within a package spec,
+            --  which is the case where we delay the analysis of the PPC until
+            --  the end of the package declarations (for details, see
+            --  Analyze_Package_Specification.Analyze_PPCs).
+
+            if not Is_Package_Or_Generic_Package (Scope (S)) then
+               Analyze_PPC_In_Decl_Part (N, S);
+            end if;
+
+            --  Chain spec PPC pragma to list for subprogram
+
+            Set_Next_Pragma (N, Spec_PPC_List (S));
+            Set_Spec_PPC_List (S, N);
+
+            --  Return indicating spec case
+
+            In_Body := False;
+            return;
+         end Chain_PPC;
+
+         --  Start of processing for Check_Precondition_Postcondition
+
+      begin
+         if not Is_List_Member (N) then
+            Pragma_Misplaced;
+         end if;
+
+         --  Record whether pragma is enabled
+
+         Set_PPC_Enabled (N, Check_Enabled (Pname));
+
+         --  If we are within an inlined body, the legality of the pragma
+         --  has been checked already.
+
+         if In_Inlined_Body then
+            In_Body := True;
+            return;
+         end if;
+
+         --  Search prior declarations
+
+         P := N;
+         while Present (Prev (P)) loop
+            P := Prev (P);
+
+            --  If the previous node is a generic subprogram, do not go to
+            --  to the original node, which is the unanalyzed tree: we need
+            --  to attach the pre/postconditions to the analyzed version
+            --  at this point. They get propagated to the original tree when
+            --  analyzing the corresponding body.
+
+            if Nkind (P) not in N_Generic_Declaration then
+               PO := Original_Node (P);
+            else
+               PO := P;
+            end if;
+
+            --  Skip past prior pragma
+
+            if Nkind (PO) = N_Pragma then
+               null;
+
+            --  Skip stuff not coming from source
+
+            elsif not Comes_From_Source (PO) then
+               null;
+
+            --  Only remaining possibility is subprogram declaration
+
+            else
+               Chain_PPC (PO);
+               return;
+            end if;
+         end loop;
+
+         --  If we fall through loop, pragma is at start of list, so see if
+         --  it is at the start of declarations of a subprogram body.
+
+         if Nkind (Parent (N)) = N_Subprogram_Body
+           and then List_Containing (N) = Declarations (Parent (N))
+         then
+            if Operating_Mode /= Generate_Code then
+
+               --  Analyze expression in pragma, for correctness
+               --  and for ASIS use.
+
+               Preanalyze_Spec_Expression
+                 (Get_Pragma_Arg (Arg1), Standard_Boolean);
+            end if;
+
+            In_Body := True;
+            return;
+
+         --  See if it is in the pragmas after a library level subprogram
+
+         elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
+            Chain_PPC (Unit (Parent (Parent (N))));
+            return;
+         end if;
+
+         --  If we fall through, pragma was misplaced
+
+         Pragma_Misplaced;
+      end Check_Precondition_Postcondition;
+
       -----------------------------
       -- Check_Static_Constraint --
       -----------------------------
@@ -1267,13 +1494,13 @@ package body Sem_Prag is
 
       procedure Check_Static_Constraint (Constr : Node_Id) is
 
+         procedure Require_Static (E : Node_Id);
+         --  Require given expression to be static expression
+
          --------------------
          -- Require_Static --
          --------------------
 
-         procedure Require_Static (E : Node_Id);
-         --  Require given expression to be static expression
-
          procedure Require_Static (E : Node_Id) is
          begin
             if not Is_OK_Static_Expression (E) then
@@ -1322,7 +1549,7 @@ package body Sem_Prag is
       --------------------------------------
 
       --  A configuration pragma must appear in the context clause of a
-      --  compilation unit, and only other pragmas may preceed it. Note that
+      --  compilation unit, and only other pragmas may precede it. Note that
       --  the test also allows use in a configuration pragma file.
 
       procedure Check_Valid_Configuration_Pragma is
@@ -1536,6 +1763,18 @@ package body Sem_Prag is
          raise Pragma_Exit;
       end Error_Pragma_Arg_Ident;
 
+      ----------------------
+      -- Error_Pragma_Ref --
+      ----------------------
+
+      procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
+      begin
+         Error_Msg_Name_1 := Pname;
+         Error_Msg_Sloc   := Sloc (Ref);
+         Error_Msg_NE (Msg, N, Ref);
+         raise Pragma_Exit;
+      end Error_Pragma_Ref;
+
       ------------------------
       -- Find_Lib_Unit_Name --
       ------------------------
@@ -1743,19 +1982,6 @@ package body Sem_Prag is
          end loop;
       end Gather_Associations;
 
-      --------------------
-      -- Get_Pragma_Arg --
-      --------------------
-
-      function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
-      begin
-         if Nkind (Arg) = N_Pragma_Argument_Association then
-            return Expression (Arg);
-         else
-            return Arg;
-         end if;
-      end Get_Pragma_Arg;
-
       -----------------
       -- GNAT_Pragma --
       -----------------
@@ -1895,10 +2121,10 @@ package body Sem_Prag is
          Utyp : Entity_Id;
 
          procedure Set_Atomic (E : Entity_Id);
-         --  Set given type as atomic, and if no explicit alignment was
-         --  given, set alignment to unknown, since back end knows what
-         --  the alignment requirements are for atomic arrays. Note that
-         --  this step is necessary for derived types.
+         --  Set given type as atomic, and if no explicit alignment was given,
+         --  set alignment to unknown, since back end knows what the alignment
+         --  requirements are for atomic arrays. Note: this step is necessary
+         --  for derived types.
 
          ----------------
          -- Set_Atomic --
@@ -1946,9 +2172,8 @@ package body Sem_Prag is
                Set_Atomic (Base_Type (E));
             end if;
 
-            --  Attribute belongs on the base type. If the
-            --  view of the type is currently private, it also
-            --  belongs on the underlying type.
+            --  Attribute belongs on the base type. If the view of the type is
+            --  currently private, it also belongs on the underlying type.
 
             Set_Is_Volatile (Base_Type (E));
             Set_Is_Volatile (Underlying_Type (E));
@@ -1967,10 +2192,9 @@ package body Sem_Prag is
             if Prag_Id /= Pragma_Volatile then
                Set_Is_Atomic (E);
 
-               --  If the object declaration has an explicit
-               --  initialization, a temporary may have to be
-               --  created to hold the expression, to insure
-               --  that access to the object remain atomic.
+               --  If the object declaration has an explicit initialization, a
+               --  temporary may have to be created to hold the expression, to
+               --  ensure that access to the object remain atomic.
 
                if Nkind (Parent (E)) = N_Object_Declaration
                  and then Present (Expression (Parent (E)))
@@ -1980,7 +2204,7 @@ package body Sem_Prag is
 
                --  An interesting improvement here. If an object of type X
                --  is declared atomic, and the type X is not atomic, that's
-               --  a pity, since it may not have appropraite alignment etc.
+               --  a pity, since it may not have appropriate alignment etc.
                --  We can rescue this in the special case where the object
                --  and type are in the same unit by just setting the type
                --  as atomic, so that the back end will process it as atomic.
@@ -2015,7 +2239,6 @@ package body Sem_Prag is
          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
 
       begin
-         GNAT_Pragma;
          Check_Arg_Count (2);
          Check_No_Identifiers;
          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
@@ -2265,9 +2488,15 @@ package body Sem_Prag is
             if Nkind (Parent (Declaration_Node (E))) =
                                        N_Subprogram_Renaming_Declaration
             then
+               if Scope (E) /= Scope (Alias (E)) then
+                  Error_Pragma_Ref
+                    ("cannot apply pragma% to non-local entity&#", E);
+               end if;
+
                E := Alias (E);
 
-            elsif Nkind (Parent (E)) = N_Full_Type_Declaration
+            elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
+                                        N_Private_Extension_Declaration)
               and then Scope (E) = Scope (Alias (E))
             then
                E := Alias (E);
@@ -2389,11 +2618,23 @@ package body Sem_Prag is
                E1 := Homonym (E1);
                exit when No (E1) or else Scope (E1) /= Current_Scope;
 
+               --  Do not set the pragma on inherited operations or on
+               --  formal subprograms.
+
                if Comes_From_Source (E1)
                  and then Comp_Unit = Get_Source_Unit (E1)
+                 and then not Is_Formal_Subprogram (E1)
                  and then Nkind (Original_Node (Parent (E1))) /=
-                   N_Full_Type_Declaration
+                                                    N_Full_Type_Declaration
                then
+                  if Present (Alias (E1))
+                    and then Scope (E1) /= Scope (Alias (E1))
+                  then
+                     Error_Pragma_Ref
+                       ("cannot apply pragma% to non-local entity& declared#",
+                        E1);
+                  end if;
+
                   Set_Convention_From_Pragma (E1);
 
                   if Prag_Id = Pragma_Import then
@@ -2418,8 +2659,6 @@ package body Sem_Prag is
          Code_Val : Uint;
 
       begin
-         GNAT_Pragma;
-
          if not OpenVMS_On_Target then
             Error_Pragma
               ("?pragma% ignored (applies only to Open'V'M'S)");
@@ -2477,8 +2716,6 @@ package body Sem_Prag is
         (Arg_Internal : Node_Id := Empty)
       is
       begin
-         GNAT_Pragma;
-
          if No (Arg_Internal) then
             Error_Pragma ("Internal parameter required for pragma%");
          end if;
@@ -2617,7 +2854,7 @@ package body Sem_Prag is
                   "\no initialization allowed for & declared#", Arg1);
             else
                Set_Imported (Def_Id);
-               Note_Possible_Modification (Arg_Internal);
+               Note_Possible_Modification (Arg_Internal, Sure => False);
             end if;
          end if;
       end Process_Extended_Import_Export_Object_Pragma;
@@ -2678,7 +2915,7 @@ package body Sem_Prag is
                end if;
 
                --  We have a match if the corresponding argument is of an
-               --  anonymous access type, and its designicated type matches
+               --  anonymous access type, and its designated type matches
                --  the type of the prefix of the access attribute
 
                return Ekind (Ftyp) = E_Anonymous_Access_Type
@@ -2730,9 +2967,8 @@ package body Sem_Prag is
                --  Pragma cannot apply to subprogram body
 
                if Is_Subprogram (Def_Id)
-                 and then
-                   Nkind (Parent
-                     (Declaration_Node (Def_Id))) = N_Subprogram_Body
+                 and then Nkind (Parent (Declaration_Node (Def_Id))) =
+                                                             N_Subprogram_Body
                then
                   Error_Pragma
                     ("pragma% requires separate spec"
@@ -2863,7 +3099,7 @@ package body Sem_Prag is
             return;
          end if;
 
-         --  Import pragmas must be be for imported entities
+         --  Import pragmas must be for imported entities
 
          if Prag_Id = Pragma_Import_Function
               or else
@@ -2887,7 +3123,7 @@ package body Sem_Prag is
          then
             null;
 
-         --  In all other cases, set entit as exported
+         --  In all other cases, set entity as exported
 
          else
             Set_Exported (Ent, Arg_Internal);
@@ -3010,6 +3246,11 @@ package body Sem_Prag is
                            if Chars (Choice) = Chars (Formal) then
                               Set_Mechanism_Value
                                 (Formal, Expression (Massoc));
+
+                              --  Set entity on identifier for ASIS
+
+                              Set_Entity (Choice, Formal);
+
                               exit;
                            end if;
 
@@ -3090,7 +3331,6 @@ package body Sem_Prag is
          Exp : Node_Id;
 
       begin
-         GNAT_Pragma;
          Check_No_Identifiers;
          Check_At_Least_N_Arguments (1);
 
@@ -3126,7 +3366,7 @@ package body Sem_Prag is
       begin
          Process_Convention (C, Def_Id);
          Kill_Size_Check_Code (Def_Id);
-         Note_Possible_Modification (Expression (Arg2));
+         Note_Possible_Modification (Expression (Arg2), Sure => False);
 
          if Ekind (Def_Id) = E_Variable
               or else
@@ -3158,7 +3398,7 @@ package body Sem_Prag is
                Process_Interface_Name (Def_Id, Arg3, Arg4);
 
                --  Note that we do not set Is_Public here. That's because we
-               --  only want to set if if there is no address clause, and we
+               --  only want to set it if there is no address clause, and we
                --  don't know that yet, so we delay that processing till
                --  freeze time.
 
@@ -3265,10 +3505,8 @@ package body Sem_Prag is
                      if Present (Decl)
                        and then Nkind (Decl) = N_Subprogram_Declaration
                        and then Present (Corresponding_Body (Decl))
-                       and then
-                         Nkind
-                           (Unit_Declaration_Node
-                             (Corresponding_Body (Decl))) =
+                       and then Nkind (Unit_Declaration_Node
+                                        (Corresponding_Body (Decl))) =
                                              N_Subprogram_Renaming_Declaration
                      then
                         Error_Msg_Sloc := Sloc (Def_Id);
@@ -3301,8 +3539,7 @@ package body Sem_Prag is
 
          elsif (C = Convention_Java or else C = Convention_CIL)
            and then
-             (Ekind (Def_Id) = E_Package
-                or else Ekind (Def_Id) = E_Generic_Package
+             (Is_Package_Or_Generic_Package (Def_Id)
                 or else Ekind (Def_Id) = E_Exception
                 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
          then
@@ -3382,7 +3619,7 @@ package body Sem_Prag is
 
          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
          --  Returns True if it can be determined at this stage that inlining
-         --  is not possible, for examle if the body is available and contains
+         --  is not possible, for example if the body is available and contains
          --  exception handlers, we prevent inlining, since otherwise we can
          --  get undefined symbols at link time. This function also emits a
          --  warning if front-end inlining is enabled and the pragma appears
@@ -3470,29 +3707,36 @@ package body Sem_Prag is
                return;
 
             --  Here we have a candidate for inlining, but we must exclude
-            --  derived operations. Otherwise we will end up trying to
-            --  inline a phantom declaration, and the result would be to
-            --  drag in a body which has no direct inlining associated with
-            --  it. That would not only be inefficient but would also result
-            --  in the backend doing cross-unit inlining in cases where it
-            --  was definitely inappropriate to do so.
-
-            --  However, a simple Comes_From_Source test is insufficient,
-            --  since we do want to allow inlining of generic instances,
-            --  which also do not come from source. Predefined operators do
-            --  not come from source but are not inlineable either.
+            --  derived operations. Otherwise we would end up trying to inline
+            --  a phantom declaration, and the result would be to drag in a
+            --  body which has no direct inlining associated with it. That
+            --  would not only be inefficient but would also result in the
+            --  backend doing cross-unit inlining in cases where it was
+            --  definitely inappropriate to do so.
+
+            --  However, a simple Comes_From_Source test is insufficient, since
+            --  we do want to allow inlining of generic instances which also do
+            --  not come from source. We also need to recognize specs
+            --  generated by the front-end for bodies that carry the pragma.
+            --  Finally, predefined operators do not come from source but are
+            --  not inlineable either.
+
+            elsif Is_Generic_Instance (Subp)
+              or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
+            then
+               null;
 
             elsif not Comes_From_Source (Subp)
-              and then not Is_Generic_Instance (Subp)
               and then Scope (Subp) /= Standard_Standard
             then
                Applies := True;
                return;
+            end if;
 
             --  The referenced entity must either be the enclosing entity,
             --  or an entity declared within the current open scope.
 
-            elsif Present (Scope (Subp))
+            if Present (Scope (Subp))
               and then Scope (Subp) /= Current_Scope
               and then Subp /= Current_Scope
             then
@@ -3520,6 +3764,22 @@ package body Sem_Prag is
                     and then Present (Corresponding_Body (Decl))
                   then
                      Set_Inline_Flags (Corresponding_Body (Decl));
+
+                  elsif Is_Generic_Instance (Subp) then
+
+                     --  Indicate that the body needs to be created for
+                     --  inlining subsequent calls. The instantiation
+                     --  node follows the declaration of the wrapper
+                     --  package created for it.
+
+                     if Scope (Subp) /= Standard_Standard
+                       and then
+                         Need_Subprogram_Instance_Body
+                          (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
+                              Subp)
+                     then
+                        null;
+                     end if;
                   end if;
                end if;
 
@@ -3638,17 +3898,23 @@ package body Sem_Prag is
          Link_Nam   : Node_Id;
          String_Val : String_Id;
 
-         procedure Check_Form_Of_Interface_Name (SN : Node_Id);
+         procedure Check_Form_Of_Interface_Name
+           (SN            : Node_Id;
+            Ext_Name_Case : Boolean);
          --  SN is a string literal node for an interface name. This routine
          --  performs some minimal checks that the name is reasonable. In
          --  particular that no spaces or other obviously incorrect characters
          --  appear. This is only a warning, since any characters are allowed.
+         --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
 
          ----------------------------------
          -- Check_Form_Of_Interface_Name --
          ----------------------------------
 
-         procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
+         procedure Check_Form_Of_Interface_Name
+           (SN            : Node_Id;
+            Ext_Name_Case : Boolean)
+         is
             S  : constant String_Id := Strval (Expr_Value_S (SN));
             SL : constant Nat       := String_Length (S);
             C  : Char_Code;
@@ -3661,15 +3927,28 @@ package body Sem_Prag is
             for J in 1 .. SL loop
                C := Get_String_Char (S, J);
 
-               if Warn_On_Export_Import
-                 and then
-                   (not In_Character_Range (C)
-                     or else (Get_Character (C) = ' '
-                               and then VM_Target /= CLI_Target)
-                     or else Get_Character (C) = ',')
+               --  Look for dubious character and issue unconditional warning.
+               --  Definitely dubious if not in character range.
+
+               if not In_Character_Range (C)
+
+                  --  For all cases except external names on CLI target,
+                  --  commas, spaces and slashes are dubious (in CLI, we use
+                  --  spaces and commas in external names to specify assembly
+                  --  version and public key).
+
+                  or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
+                             and then (Get_Character (C) = ' '
+                                         or else
+                                       Get_Character (C) = ','
+                                         or else
+                                       Get_Character (C) = '/'
+                                         or else
+                                       Get_Character (C) = '\'))
                then
-                  Error_Msg_N
-                    ("?interface name contains illegal character", SN);
+                  Error_Msg
+                    ("?interface name contains illegal character",
+                     Sloc (SN) + Source_Ptr (J));
                end if;
             end loop;
          end Check_Form_Of_Interface_Name;
@@ -3714,13 +3993,13 @@ package body Sem_Prag is
 
          if Present (Ext_Nam) then
             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
-            Check_Form_Of_Interface_Name (Ext_Nam);
+            Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
 
-            --  Verify that the external name is not the name of a local
-            --  entity, which would hide the imported one and lead to
-            --  run-time surprises. The problem can only arise for entities
-            --  declared in a package body (otherwise the external name is
-            --  fully qualified and won't conflict).
+            --  Verify that external name is not the name of a local entity,
+            --  which would hide the imported one and could lead to run-time
+            --  surprises. The problem can only arise for entities declared in
+            --  a package body (otherwise the external name is fully qualified
+            --  and will not conflict).
 
             declare
                Nam : Name_Id;
@@ -3743,10 +4022,10 @@ package body Sem_Prag is
                      Par := Parent (E);
                      while Present (Par) loop
                         if Nkind (Par) = N_Package_Body then
-                           Error_Msg_Sloc  := Sloc (E);
+                           Error_Msg_Sloc := Sloc (E);
                            Error_Msg_NE
                              ("imported entity is hidden by & declared#",
-                                 Ext_Arg, E);
+                              Ext_Arg, E);
                            exit;
                         end if;
 
@@ -3759,7 +4038,7 @@ package body Sem_Prag is
 
          if Present (Link_Nam) then
             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
-            Check_Form_Of_Interface_Name (Link_Nam);
+            Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
          end if;
 
          --  If there is no link name, just set the external name
@@ -3884,13 +4163,40 @@ package body Sem_Prag is
                    (Process_Restriction_Synonyms (Expr));
 
                if R_Id not in All_Boolean_Restrictions then
-                  Error_Pragma_Arg
-                    ("invalid restriction identifier", Arg);
+                  Error_Msg_Name_1 := Pname;
+                  Error_Msg_N
+                    ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
+
+                  --  Check for possible misspelling
+
+                  for J in Restriction_Id loop
+                     declare
+                        Rnm : constant String := Restriction_Id'Image (J);
+
+                     begin
+                        Name_Buffer (1 .. Rnm'Length) := Rnm;
+                        Name_Len := Rnm'Length;
+                        Set_Casing (All_Lower_Case);
+
+                        if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
+                           Set_Casing
+                             (Identifier_Casing (Current_Source_File));
+                           Error_Msg_String (1 .. Rnm'Length) :=
+                             Name_Buffer (1 .. Name_Len);
+                           Error_Msg_Strlen := Rnm'Length;
+                           Error_Msg_N
+                             ("\possible misspelling of ""~""",
+                              Get_Pragma_Arg (Arg));
+                           exit;
+                        end if;
+                     end;
+                  end loop;
+
+                  raise Pragma_Exit;
                end if;
 
                if Implementation_Restriction (R_Id) then
-                  Check_Restriction
-                    (No_Implementation_Restrictions, Arg);
+                  Check_Restriction (No_Implementation_Restrictions, Arg);
                end if;
 
                --  If this is a warning, then set the warning unless we already
@@ -4000,9 +4306,7 @@ package body Sem_Prag is
          E    : Entity_Id;
 
          In_Package_Spec : constant Boolean :=
-                             (Ekind (Current_Scope) = E_Package
-                                or else
-                              Ekind (Current_Scope) = E_Generic_Package)
+                             Is_Package_Or_Generic_Package (Current_Scope)
                                and then not In_Package_Body (Current_Scope);
 
          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
@@ -4363,6 +4667,7 @@ package body Sem_Prag is
       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
          Class : Node_Id;
          Param : Node_Id;
+         Mech_Name_Id : Name_Id;
 
          procedure Bad_Class;
          --  Signal bad descriptor class name
@@ -4396,7 +4701,8 @@ package body Sem_Prag is
               ("mechanism for & has already been set", Mech_Name, Ent);
          end if;
 
-         --  MECHANISM_NAME ::= value | reference | descriptor
+         --  MECHANISM_NAME ::= value | reference | descriptor |
+         --                     short_descriptor
 
          if Nkind (Mech_Name) = N_Identifier then
             if Chars (Mech_Name) = Name_Value then
@@ -4412,6 +4718,11 @@ package body Sem_Prag is
                Set_Mechanism (Ent, By_Descriptor);
                return;
 
+            elsif Chars (Mech_Name) = Name_Short_Descriptor then
+               Check_VMS (Mech_Name);
+               Set_Mechanism (Ent, By_Short_Descriptor);
+               return;
+
             elsif Chars (Mech_Name) = Name_Copy then
                Error_Pragma_Arg
                  ("bad mechanism name, Value assumed", Mech_Name);
@@ -4420,22 +4731,28 @@ package body Sem_Prag is
                Bad_Mechanism;
             end if;
 
-         --  MECHANISM_NAME ::= descriptor (CLASS_NAME)
+         --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
+         --                     short_descriptor (CLASS_NAME)
          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
 
          --  Note: this form is parsed as an indexed component
 
          elsif Nkind (Mech_Name) = N_Indexed_Component then
+
             Class := First (Expressions (Mech_Name));
 
             if Nkind (Prefix (Mech_Name)) /= N_Identifier
-              or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
-              or else Present (Next (Class))
+             or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
+                          Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
+             or else Present (Next (Class))
             then
                Bad_Mechanism;
+            else
+               Mech_Name_Id := Chars (Prefix (Mech_Name));
             end if;
 
-         --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
+         --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
+         --                     short_descriptor (Class => CLASS_NAME)
          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
 
          --  Note: this form is parsed as a function call
@@ -4445,7 +4762,8 @@ package body Sem_Prag is
             Param := First (Parameter_Associations (Mech_Name));
 
             if Nkind (Name (Mech_Name)) /= N_Identifier
-              or else Chars (Name (Mech_Name)) /= Name_Descriptor
+              or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
+                           Chars (Name (Mech_Name)) = Name_Short_Descriptor)
               or else Present (Next (Param))
               or else No (Selector_Name (Param))
               or else Chars (Selector_Name (Param)) /= Name_Class
@@ -4453,6 +4771,7 @@ package body Sem_Prag is
                Bad_Mechanism;
             else
                Class := Explicit_Actual_Parameter (Param);
+               Mech_Name_Id := Chars (Name (Mech_Name));
             end if;
 
          else
@@ -4466,27 +4785,76 @@ package body Sem_Prag is
          if Nkind (Class) /= N_Identifier then
             Bad_Class;
 
-         elsif Chars (Class) = Name_UBS then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_UBS
+         then
             Set_Mechanism (Ent, By_Descriptor_UBS);
 
-         elsif Chars (Class) = Name_UBSB then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_UBSB
+         then
             Set_Mechanism (Ent, By_Descriptor_UBSB);
 
-         elsif Chars (Class) = Name_UBA then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_UBA
+         then
             Set_Mechanism (Ent, By_Descriptor_UBA);
 
-         elsif Chars (Class) = Name_S then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_S
+         then
             Set_Mechanism (Ent, By_Descriptor_S);
 
-         elsif Chars (Class) = Name_SB then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_SB
+         then
             Set_Mechanism (Ent, By_Descriptor_SB);
 
-         elsif Chars (Class) = Name_A then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_A
+         then
             Set_Mechanism (Ent, By_Descriptor_A);
 
-         elsif Chars (Class) = Name_NCA then
+         elsif Mech_Name_Id = Name_Descriptor
+               and then Chars (Class) = Name_NCA
+         then
             Set_Mechanism (Ent, By_Descriptor_NCA);
 
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_UBS
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_UBS);
+
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_UBSB
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
+
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_UBA
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_UBA);
+
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_S
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_S);
+
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_SB
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_SB);
+
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_A
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_A);
+
+         elsif Mech_Name_Id = Name_Short_Descriptor
+               and then Chars (Class) = Name_NCA
+         then
+            Set_Mechanism (Ent, By_Short_Descriptor_NCA);
+
          else
             Bad_Class;
          end if;
@@ -4554,7 +4922,8 @@ package body Sem_Prag is
 
          --  Set the corresponding restrictions
 
-         Set_Profile_Restrictions (Ravenscar, N, Warn => False);
+         Set_Profile_Restrictions
+           (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
       end Set_Ravenscar_Profile;
 
    --  Start of processing for Analyze_Pragma
@@ -4621,7 +4990,7 @@ package body Sem_Prag is
       end;
 
       --  An enumeration type defines the pragmas that are supported by the
-      --  implementation. Get_Pragma_Id (in package Prag) transorms a name
+      --  implementation. Get_Pragma_Id (in package Prag) transforms a name
       --  into the corresponding enumeration value for the following case.
 
       case Prag_Id is
@@ -4840,7 +5209,7 @@ package body Sem_Prag is
 
          when Pragma_Assert => Assert : declare
             Expr : Node_Id;
-            Eloc : Source_Ptr;
+            Newa : List_Id;
 
          begin
             Ada_2005_Pragma;
@@ -4849,71 +5218,33 @@ package body Sem_Prag is
             Check_Arg_Order ((Name_Check, Name_Message));
             Check_Optional_Identifier (Arg1, Name_Check);
 
-            if Arg_Count > 1 then
-               Check_Optional_Identifier (Arg2, Name_Message);
-               Check_Arg_Is_Static_Expression (Arg2, Standard_String);
-            end if;
-
-            --  If expansion is active and assertions are inactive, then
-            --  we rewrite the Assertion as:
-
-            --    if False and then condition then
-            --       null;
-            --    end if;
-
-            --  The reason we do this rewriting during semantic analysis rather
-            --  than as part of normal expansion is that we cannot analyze and
-            --  expand the code for the boolean expression directly, or it may
-            --  cause insertion of actions that would escape the attempt to
-            --  suppress the assertion code.
-
-            --  Note that the Sloc for the if statement corresponds to the
-            --  argument condition, not the pragma itself. The reason for this
-            --  is that we may generate a warning if the condition is False at
-            --  compile time, and we do not want to delete this warning when we
-            --  delete the if statement.
+            --  We treat pragma Assert as equivalent to:
 
-            Expr := Expression (Arg1);
-            Eloc := Sloc (Expr);
+            --    pragma Check (Assertion, condition [, msg]);
 
-            if Expander_Active and not Assertions_Enabled then
-               Rewrite (N,
-                 Make_If_Statement (Eloc,
-                   Condition =>
-                     Make_And_Then (Eloc,
-                       Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
-                       Right_Opnd => Expr),
-                   Then_Statements => New_List (
-                     Make_Null_Statement (Eloc))));
+            --  So rewrite pragma in this manner, and analyze the result
 
-               Analyze (N);
+            Expr := Get_Pragma_Arg (Arg1);
+            Newa := New_List (
+              Make_Pragma_Argument_Association (Loc,
+                Expression =>
+                  Make_Identifier (Loc,
+                    Chars => Name_Assertion)),
 
-            --  Otherwise (if assertions are enabled, or if we are not
-            --  operating with expansion active), then we just analyze
-            --  and resolve the expression.
+              Make_Pragma_Argument_Association (Sloc (Expr),
+                Expression => Expr));
 
-            else
-               Analyze_And_Resolve (Expr, Any_Boolean);
+            if Arg_Count > 1 then
+               Check_Optional_Identifier (Arg2, Name_Message);
+               Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
+               Append_To (Newa, Relocate_Node (Arg2));
             end if;
 
-            --  If assertion is of the form (X'First = literal), where X is
-            --  formal parameter, then set Low_Bound_Known flag on this formal.
-
-            if Nkind (Expr) = N_Op_Eq then
-               declare
-                  Right : constant Node_Id := Right_Opnd (Expr);
-                  Left  : constant Node_Id := Left_Opnd  (Expr);
-               begin
-                  if Nkind (Left) = N_Attribute_Reference
-                    and then Attribute_Name (Left) = Name_First
-                    and then Is_Entity_Name (Prefix (Left))
-                    and then Is_Formal (Entity (Prefix (Left)))
-                    and then Nkind (Right) = N_Integer_Literal
-                  then
-                     Set_Low_Bound_Known (Entity (Prefix (Left)));
-                  end if;
-               end;
-            end if;
+            Rewrite (N,
+              Make_Pragma (Loc,
+                Chars => Name_Check,
+                Pragma_Argument_Associations => Newa));
+            Analyze (N);
          end Assert;
 
          ----------------------
@@ -4922,20 +5253,72 @@ package body Sem_Prag is
 
          --  pragma Assertion_Policy (Check | Ignore)
 
-         when Pragma_Assertion_Policy =>
+         when Pragma_Assertion_Policy => Assertion_Policy : declare
+            Policy : Node_Id;
+
+         begin
             Ada_2005_Pragma;
+            Check_Valid_Configuration_Pragma;
             Check_Arg_Count (1);
+            Check_No_Identifiers;
             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
-            Assertions_Enabled := Chars (Expression (Arg1)) = Name_Check;
 
-         ---------------
-         -- AST_Entry --
-         ---------------
+            --  We treat pragma Assertion_Policy as equivalent to:
 
-         --  pragma AST_Entry (entry_IDENTIFIER);
+            --    pragma Check_Policy (Assertion, policy)
 
-         when Pragma_AST_Entry => AST_Entry : declare
-            Ent : Node_Id;
+            --  So rewrite the pragma in that manner and link on to the chain
+            --  of Check_Policy pragmas, marking the pragma as analyzed.
+
+            Policy := Get_Pragma_Arg (Arg1);
+
+            Rewrite (N,
+              Make_Pragma (Loc,
+                Chars => Name_Check_Policy,
+
+                Pragma_Argument_Associations => New_List (
+                  Make_Pragma_Argument_Association (Loc,
+                    Expression =>
+                      Make_Identifier (Loc,
+                        Chars => Name_Assertion)),
+
+                  Make_Pragma_Argument_Association (Loc,
+                    Expression =>
+                      Make_Identifier (Sloc (Policy),
+                        Chars => Chars (Policy))))));
+
+            Set_Analyzed (N);
+            Set_Next_Pragma (N, Opt.Check_Policy_List);
+            Opt.Check_Policy_List := N;
+         end Assertion_Policy;
+
+         ------------------------------
+         -- Assume_No_Invalid_Values --
+         ------------------------------
+
+         --  pragma Assume_No_Invalid_Values (On | Off);
+
+         when Pragma_Assume_No_Invalid_Values =>
+            GNAT_Pragma;
+            Check_Valid_Configuration_Pragma;
+            Check_Arg_Count (1);
+            Check_No_Identifiers;
+            Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
+
+            if Chars (Expression (Arg1)) = Name_On then
+               Assume_No_Invalid_Values := True;
+            else
+               Assume_No_Invalid_Values := False;
+            end if;
+
+         ---------------
+         -- AST_Entry --
+         ---------------
+
+         --  pragma AST_Entry (entry_IDENTIFIER);
+
+         when Pragma_AST_Entry => AST_Entry : declare
+            Ent : Node_Id;
 
          begin
             GNAT_Pragma;
@@ -5237,7 +5620,7 @@ package body Sem_Prag is
                               New_Copy_Tree (Expression (Arg2));
                   begin
                      Set_Parent (Temp, N);
-                     Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
+                     Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
                   end;
 
                else
@@ -5285,6 +5668,97 @@ package body Sem_Prag is
             end if;
          end C_Pass_By_Copy;
 
+         -----------
+         -- Check --
+         -----------
+
+         --  pragma Check ([Name    =>] Identifier,
+         --                [Check   =>] Boolean_Expression
+         --              [,[Message =>] String_Expression]);
+
+         when Pragma_Check => Check : declare
+            Expr : Node_Id;
+            Eloc : Source_Ptr;
+
+            Check_On : Boolean;
+            --  Set True if category of assertions referenced by Name enabled
+
+         begin
+            GNAT_Pragma;
+            Check_At_Least_N_Arguments (2);
+            Check_At_Most_N_Arguments (3);
+            Check_Optional_Identifier (Arg1, Name_Name);
+            Check_Optional_Identifier (Arg2, Name_Check);
+
+            if Arg_Count = 3 then
+               Check_Optional_Identifier (Arg3, Name_Message);
+               Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
+            end if;
+
+            Check_Arg_Is_Identifier (Arg1);
+            Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
+
+            --  If expansion is active and the check is not enabled then we
+            --  rewrite the Check as:
+
+            --    if False and then condition then
+            --       null;
+            --    end if;
+
+            --  The reason we do this rewriting during semantic analysis rather
+            --  than as part of normal expansion is that we cannot analyze and
+            --  expand the code for the boolean expression directly, or it may
+            --  cause insertion of actions that would escape the attempt to
+            --  suppress the check code.
+
+            --  Note that the Sloc for the if statement corresponds to the
+            --  argument condition, not the pragma itself. The reason for this
+            --  is that we may generate a warning if the condition is False at
+            --  compile time, and we do not want to delete this warning when we
+            --  delete the if statement.
+
+            Expr := Expression (Arg2);
+
+            if Expander_Active and then not Check_On then
+               Eloc := Sloc (Expr);
+
+               Rewrite (N,
+                 Make_If_Statement (Eloc,
+                   Condition =>
+                     Make_And_Then (Eloc,
+                       Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
+                       Right_Opnd => Expr),
+                   Then_Statements => New_List (
+                     Make_Null_Statement (Eloc))));
+
+               Analyze (N);
+
+            --  Check is active
+
+            else
+               Analyze_And_Resolve (Expr, Any_Boolean);
+            end if;
+
+            --  If assertion is of the form (X'First = literal), where X is
+            --  a formal, then set Low_Bound_Known flag on this formal.
+
+            if Nkind (Expr) = N_Op_Eq then
+               declare
+                  Right : constant Node_Id := Right_Opnd (Expr);
+                  Left  : constant Node_Id := Left_Opnd  (Expr);
+               begin
+                  if Nkind (Left) = N_Attribute_Reference
+                    and then Attribute_Name (Left) = Name_First
+                    and then Is_Entity_Name (Prefix (Left))
+                    and then Is_Formal (Entity (Prefix (Left)))
+                    and then Nkind (Right) = N_Integer_Literal
+                  then
+                     Set_Low_Bound_Known (Entity (Prefix (Left)));
+                  end if;
+               end;
+            end if;
+         end Check;
+
          ----------------
          -- Check_Name --
          ----------------
@@ -5311,6 +5785,38 @@ package body Sem_Prag is
                Check_Names.Append (Nam);
             end;
 
+         ------------------
+         -- Check_Policy --
+         ------------------
+
+         --  pragma Check_Policy ([Name =>] IDENTIFIER,
+         --                       POLICY_IDENTIFIER;
+
+         --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
+
+         --  Note: this is a configuration pragma, but it is allowed to
+         --  appear anywhere else.
+
+         when Pragma_Check_Policy =>
+            GNAT_Pragma;
+            Check_Arg_Count (2);
+            Check_No_Identifier (Arg2);
+            Check_Optional_Identifier (Arg1, Name_Name);
+            Check_Arg_Is_One_Of
+              (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
+
+            --  A Check_Policy pragma can appear either as a configuration
+            --  pragma, or in a declarative part or a package spec (see RM
+            --  11.5(5) for rules for Suppress/Unsuppress which are also
+            --  followed for Check_Policy).
+
+            if not Is_Configuration_Pragma then
+               Check_Is_In_Decl_Part_Or_Package_Spec;
+            end if;
+
+            Set_Next_Pragma (N, Opt.Check_Policy_List);
+            Opt.Check_Policy_List := N;
+
          ---------------------
          -- CIL_Constructor --
          ---------------------
@@ -5325,11 +5831,11 @@ package body Sem_Prag is
 
          --  pragma Comment (static_string_EXPRESSION)
 
-         --  Processing for pragma Comment shares the circuitry for
-         --  pragma Ident. The only differences are that Ident enforces
-         --  a limit of 31 characters on its argument, and also enforces
-         --  limitations on placement for DEC compatibility. Pragma
-         --  Comment shares neither of these restrictions.
+         --  Processing for pragma Comment shares the circuitry for pragma
+         --  Ident. The only differences are that Ident enforces a limit of 31
+         --  characters on its argument, and also enforces limitations on
+         --  placement for DEC compatibility. Pragma Comment shares neither of
+         --  these restrictions.
 
          -------------------
          -- Common_Object --
@@ -5350,6 +5856,7 @@ package body Sem_Prag is
          --    (boolean_EXPRESSION, static_string_EXPRESSION);
 
          when Pragma_Compile_Time_Error =>
+            GNAT_Pragma;
             Process_Compile_Time_Warning_Or_Error;
 
          --------------------------
@@ -5360,6 +5867,7 @@ package body Sem_Prag is
          --    (boolean_EXPRESSION, static_string_EXPRESSION);
 
          when Pragma_Compile_Time_Warning =>
+            GNAT_Pragma;
             Process_Compile_Time_Warning_Or_Error;
 
          -------------------
@@ -5734,6 +6242,8 @@ package body Sem_Prag is
 
          when Pragma_CPP_Virtual => CPP_Virtual : declare
          begin
+            GNAT_Pragma;
+
             if Warn_On_Obsolescent_Feature then
                Error_Msg_N
                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
@@ -5747,6 +6257,8 @@ package body Sem_Prag is
 
          when Pragma_CPP_Vtable => CPP_Vtable : declare
          begin
+            GNAT_Pragma;
+
             if Warn_On_Obsolescent_Feature then
                Error_Msg_N
                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
@@ -5825,8 +6337,8 @@ package body Sem_Prag is
          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
 
          when Pragma_Discard_Names => Discard_Names : declare
-            E_Id : Entity_Id;
             E    : Entity_Id;
+            E_Id : Entity_Id;
 
          begin
             Check_Ada_83_Warning;
@@ -5856,6 +6368,7 @@ package body Sem_Prag is
                   Check_Arg_Count (1);
                   Check_Optional_Identifier (Arg1, Name_On);
                   Check_Arg_Is_Local_Name (Arg1);
+
                   E_Id := Expression (Arg1);
 
                   if Etype (E_Id) = Any_Type then
@@ -5865,8 +6378,8 @@ package body Sem_Prag is
                   end if;
 
                   if (Is_First_Subtype (E)
-                       and then (Is_Enumeration_Type (E)
-                                  or else Is_Tagged_Type (E)))
+                      and then
+                        (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
                     or else Ekind (E) = E_Exception
                   then
                      Set_Discard_Names (E);
@@ -5874,6 +6387,7 @@ package body Sem_Prag is
                      Error_Pragma_Arg
                        ("inappropriate entity for pragma%", Arg1);
                   end if;
+
                end if;
             end if;
          end Discard_Names;
@@ -5944,7 +6458,7 @@ package body Sem_Prag is
                      --  compilation unit. If the pragma appears in some unit
                      --  in the context, there might still be a need for an
                      --  Elaborate_All_Desirable from the current compilation
-                     --  to the the named unit, so we keep the check enabled.
+                     --  to the named unit, so we keep the check enabled.
 
                      if In_Extended_Main_Source_Unit (N) then
                         Set_Suppress_Elaboration_Warnings
@@ -5966,7 +6480,7 @@ package body Sem_Prag is
             end loop Outer;
 
             --  Give a warning if operating in static mode with -gnatwl
-            --  (elaboration warnings eanbled) switch set.
+            --  (elaboration warnings enabled) switch set.
 
             if Elab_Warnings and not Dynamic_Elaboration_Checks then
                Error_Msg_N
@@ -6219,11 +6733,27 @@ package body Sem_Prag is
             Process_Convention (C, Def_Id);
 
             if Ekind (Def_Id) /= E_Constant then
-               Note_Possible_Modification (Expression (Arg2));
+               Note_Possible_Modification (Expression (Arg2), Sure => False);
             end if;
 
             Process_Interface_Name (Def_Id, Arg3, Arg4);
             Set_Exported (Def_Id, Arg2);
+
+            --  If the entity is a deferred constant, propagate the
+            --  information to the full view, because gigi elaborates
+            --  the full view only.
+
+            if Ekind (Def_Id) = E_Constant
+              and then Present (Full_View (Def_Id))
+            then
+               declare
+                  Id2 : constant Entity_Id := Full_View (Def_Id);
+               begin
+                  Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
+                  Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
+                  Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
+               end;
+            end if;
          end Export;
 
          ----------------------
@@ -6250,6 +6780,8 @@ package body Sem_Prag is
             Code     : Node_Id renames Args (4);
 
          begin
+            GNAT_Pragma;
+
             if Inside_A_Generic then
                Error_Pragma ("pragma% cannot be used for generic entities");
             end if;
@@ -6611,7 +7143,7 @@ package body Sem_Prag is
             Check_At_Least_N_Arguments (2);
             Check_At_Most_N_Arguments  (4);
             Process_Convention (C, Def_Id);
-            Note_Possible_Modification (Expression (Arg2));
+            Note_Possible_Modification (Expression (Arg2), Sure => False);
             Process_Interface_Name (Def_Id, Arg3, Arg4);
             Set_Exported (Def_Id, Arg2);
          end External;
@@ -6719,6 +7251,7 @@ package body Sem_Prag is
             Typ     : Entity_Id;
 
          begin
+            GNAT_Pragma;
             Check_No_Identifiers;
             Check_Arg_Count (1);
             Check_Arg_Is_Local_Name (Arg1);
@@ -7052,6 +7585,7 @@ package body Sem_Prag is
             Code     : Node_Id renames Args (4);
 
          begin
+            GNAT_Pragma;
             Gather_Associations (Names, Args);
 
             if Present (External) and then Present (Code) then
@@ -7337,6 +7871,7 @@ package body Sem_Prag is
          --  pragma Inline_Always ( NAME {, NAME} );
 
          when Pragma_Inline_Always =>
+            GNAT_Pragma;
             Process_Inline (True);
 
          --------------------
@@ -7346,6 +7881,7 @@ package body Sem_Prag is
          --  pragma Inline_Generic (NAME {, NAME});
 
          when Pragma_Inline_Generic =>
+            GNAT_Pragma;
             Process_Generic_List;
 
          ----------------------
@@ -7431,12 +7967,12 @@ package body Sem_Prag is
                Def_Id := Entity (Id);
             end if;
 
-            --  Special DEC-compatible processing for the object case,
-            --  forces object to be imported.
+            --  Special DEC-compatible processing for the object case, forces
+            --  object to be imported.
 
             if Ekind (Def_Id) = E_Variable then
                Kill_Size_Check_Code (Def_Id);
-               Note_Possible_Modification (Id);
+               Note_Possible_Modification (Id, Sure => False);
 
                --  Initialization is not allowed for imported variable
 
@@ -7543,7 +8079,7 @@ package body Sem_Prag is
                --  described in "Handling of Default and Per-Object
                --  Expressions" in sem.ads.
 
-               Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
+               Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
             end if;
 
             if Nkind (P) /= N_Task_Definition
@@ -8065,22 +8601,20 @@ package body Sem_Prag is
             Check_No_Identifiers;
             Check_Arg_Count (1);
             Check_Is_In_Decl_Part_Or_Package_Spec;
+            Check_Arg_Is_Static_Expression (Arg1, Standard_String);
+            Start_String (Strval (Expr_Value_S (Expression (Arg1))));
+
+            Arg := Arg2;
+            while Present (Arg) loop
+               Check_Arg_Is_Static_Expression (Arg, Standard_String);
+               Store_String_Char (ASCII.NUL);
+               Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
+               Arg := Next (Arg);
+            end loop;
 
             if Operating_Mode = Generate_Code
               and then In_Extended_Main_Source_Unit (N)
             then
-               Check_Arg_Is_Static_Expression (Arg1, Standard_String);
-               Start_String (Strval (Expr_Value_S (Expression (Arg1))));
-
-               Arg := Arg2;
-               while Present (Arg) loop
-                  Check_Arg_Is_Static_Expression (Arg, Standard_String);
-                  Store_String_Char (ASCII.NUL);
-                  Store_String_Chars
-                    (Strval (Expr_Value_S (Expression (Arg))));
-                  Arg := Next (Arg);
-               end loop;
-
                Store_Linker_Option_String (End_String);
             end if;
          end Linker_Options;
@@ -8102,6 +8636,12 @@ package body Sem_Prag is
             Check_Arg_Is_Library_Level_Local_Name (Arg1);
             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
 
+            --  This pragma applies only to objects
+
+            if not Is_Object (Entity (Expression (Arg1))) then
+               Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
+            end if;
+
             --  The only processing required is to link this item on to the
             --  list of rep items for the given entity. This is accomplished
             --  by the call to Rep_Item_Too_Late (when no error is detected
@@ -8372,7 +8912,8 @@ package body Sem_Prag is
          --  it was misplaced.
 
          when Pragma_No_Body =>
-            Error_Pragma ("misplaced pragma %");
+            GNAT_Pragma;
+            Pragma_Misplaced;
 
          ---------------
          -- No_Return --
@@ -8438,13 +8979,43 @@ package body Sem_Prag is
             end loop;
          end No_Return;
 
+         -----------------
+         -- No_Run_Time --
+         -----------------
+
+         --  pragma No_Run_Time;
+
+         --  Note: this pragma is retained for backwards compatibility.
+         --  See body of Rtsfind for full details on its handling.
+
+         when Pragma_No_Run_Time =>
+            GNAT_Pragma;
+            Check_Valid_Configuration_Pragma;
+            Check_Arg_Count (0);
+
+            No_Run_Time_Mode           := True;
+            Configurable_Run_Time_Mode := True;
+
+            --  Set Duration to 32 bits if word size is 32
+
+            if Ttypes.System_Word_Size = 32 then
+               Duration_32_Bits_On_Target := True;
+            end if;
+
+            --  Set appropriate restrictions
+
+            Set_Restriction (No_Finalization, N);
+            Set_Restriction (No_Exception_Handlers, N);
+            Set_Restriction (Max_Tasks, N, 0);
+            Set_Restriction (No_Tasking, N);
+
          ------------------------
          -- No_Strict_Aliasing --
          ------------------------
 
          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
 
-         when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
+         when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
             E_Id : Entity_Id;
 
          begin
@@ -8468,7 +9039,20 @@ package body Sem_Prag is
 
                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
             end if;
-         end No_Strict_Alias;
+         end No_Strict_Aliasing;
+
+         -----------------------
+         -- Normalize_Scalars --
+         -----------------------
+
+         --  pragma Normalize_Scalars;
+
+         when Pragma_Normalize_Scalars =>
+            Check_Ada_83_Warning;
+            Check_Arg_Count (0);
+            Check_Valid_Configuration_Pragma;
+            Normalize_Scalars := True;
+            Init_Or_Norm_Scalars := True;
 
          -----------------
          -- Obsolescent --
@@ -8503,9 +9087,11 @@ package body Sem_Prag is
                if Present (Ename) then
 
                   --  If entity name matches, we are fine
+                  --  Save entity in pragma argument, for ASIS use.
 
                   if Chars (Ename) = Chars (Ent) then
-                     null;
+                     Set_Entity (Ename, Ent);
+                     Generate_Reference (Ent, Ename);
 
                   --  If entity name does not match, only possibility is an
                   --  enumeration literal from an enumeration type declaration.
@@ -8523,6 +9109,8 @@ package body Sem_Prag is
                               "enumeration literal");
 
                         elsif Chars (Ent) = Chars (Ename) then
+                           Set_Entity (Ename, Ent);
+                           Generate_Reference (Ent, Ename);
                            exit;
 
                         else
@@ -8549,7 +9137,8 @@ package body Sem_Prag is
                      end if;
                   end loop;
 
-                  Set_Obsolescent_Warning (Ent, Expression (Arg1));
+                  Obsolescent_Warnings.Append
+                    ((Ent => Ent, Msg => Strval (Expression (Arg1))));
 
                   --  Check for Ada_05 parameter
 
@@ -8648,9 +9237,7 @@ package body Sem_Prag is
                   declare
                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
                   begin
-                     if Ekind (Ent) = E_Package
-                       or else Ekind (Ent) = E_Generic_Package
-                     then
+                     if Is_Package_Or_Generic_Package (Ent) then
                         Set_Obsolescent (Ent);
                         return;
                      end if;
@@ -8675,49 +9262,6 @@ package body Sem_Prag is
             end if;
          end Obsolescent;
 
-         -----------------
-         -- No_Run_Time --
-         -----------------
-
-         --  pragma No_Run_Time
-
-         --  Note: this pragma is retained for backwards compatibiltiy.
-         --  See body of Rtsfind for full details on its handling.
-
-         when Pragma_No_Run_Time =>
-            GNAT_Pragma;
-            Check_Valid_Configuration_Pragma;
-            Check_Arg_Count (0);
-
-            No_Run_Time_Mode           := True;
-            Configurable_Run_Time_Mode := True;
-
-            --  Set Duration to 32 bits if word size is 32
-
-            if Ttypes.System_Word_Size = 32 then
-               Duration_32_Bits_On_Target := True;
-            end if;
-
-            --  Set appropriate restrictions
-
-            Set_Restriction (No_Finalization, N);
-            Set_Restriction (No_Exception_Handlers, N);
-            Set_Restriction (Max_Tasks, N, 0);
-            Set_Restriction (No_Tasking, N);
-
-         -----------------------
-         -- Normalize_Scalars --
-         -----------------------
-
-         --  pragma Normalize_Scalars;
-
-         when Pragma_Normalize_Scalars =>
-            Check_Ada_83_Warning;
-            Check_Arg_Count (0);
-            Check_Valid_Configuration_Pragma;
-            Normalize_Scalars := True;
-            Init_Or_Norm_Scalars := True;
-
          --------------
          -- Optimize --
          --------------
@@ -8760,6 +9304,12 @@ package body Sem_Prag is
                end case;
             end;
 
+            --  Set indication that mode is set locally. If we are in fact in a
+            --  configuration pragma file, this setting is harmless since the
+            --  switch will get reset anyway at the start of each unit.
+
+            Optimize_Alignment_Local := True;
+
          ----------
          -- Pack --
          ----------
@@ -8948,19 +9498,6 @@ package body Sem_Prag is
             end if;
          end Preelab_Init;
 
-         -------------
-         -- Polling --
-         -------------
-
-         --  pragma Polling (ON | OFF);
-
-         when Pragma_Polling =>
-            GNAT_Pragma;
-            Check_Arg_Count (1);
-            Check_No_Identifiers;
-            Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
-            Polling_Required := (Chars (Expression (Arg1)) = Name_On);
-
          --------------------
          -- Persistent_BSS --
          --------------------
@@ -9019,6 +9556,95 @@ package body Sem_Prag is
             end if;
          end Persistent_BSS;
 
+         -------------
+         -- Polling --
+         -------------
+
+         --  pragma Polling (ON | OFF);
+
+         when Pragma_Polling =>
+            GNAT_Pragma;
+            Check_Arg_Count (1);
+            Check_No_Identifiers;
+            Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
+            Polling_Required := (Chars (Expression (Arg1)) = Name_On);
+
+         -------------------
+         -- Postcondition --
+         -------------------
+
+         --  pragma Postcondition ([Check   =>] Boolean_Expression
+         --                      [,[Message =>] String_Expression]);
+
+         when Pragma_Postcondition => Postcondition : declare
+            In_Body : Boolean;
+            pragma Warnings (Off, In_Body);
+
+         begin
+            GNAT_Pragma;
+            Check_At_Least_N_Arguments (1);
+            Check_At_Most_N_Arguments (2);
+            Check_Optional_Identifier (Arg1, Name_Check);
+
+            --  All we need to do here is call the common check procedure,
+            --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
+
+            Check_Precondition_Postcondition (In_Body);
+         end Postcondition;
+
+         ------------------
+         -- Precondition --
+         ------------------
+
+         --  pragma Precondition ([Check   =>] Boolean_Expression
+         --                     [,[Message =>] String_Expression]);
+
+         when Pragma_Precondition => Precondition : declare
+            In_Body : Boolean;
+
+         begin
+            GNAT_Pragma;
+            Check_At_Least_N_Arguments (1);
+            Check_At_Most_N_Arguments (2);
+            Check_Optional_Identifier (Arg1, Name_Check);
+
+            Check_Precondition_Postcondition (In_Body);
+
+            --  If in spec, nothing to do. If in body, then we convert the
+            --  pragma to pragma Check (Precondition, cond [, msg]). Note we
+            --  do this whether or not precondition checks are enabled. That
+            --  works fine since pragma Check will do this check.
+
+            if In_Body then
+               if Arg_Count = 2 then
+                  Check_Optional_Identifier (Arg3, Name_Message);
+                  Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
+               end if;
+
+               Analyze_And_Resolve (Get_Pragma_Arg (Arg1), Standard_Boolean);
+
+               Rewrite (N,
+                 Make_Pragma (Loc,
+                   Chars => Name_Check,
+                   Pragma_Argument_Associations => New_List (
+                     Make_Pragma_Argument_Association (Loc,
+                       Expression =>
+                         Make_Identifier (Loc,
+                           Chars => Name_Precondition)),
+
+                     Make_Pragma_Argument_Association (Sloc (Arg1),
+                       Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
+
+               if Arg_Count = 2 then
+                  Append_To (Pragma_Argument_Associations (N),
+                    Make_Pragma_Argument_Association (Sloc (Arg2),
+                      Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
+               end if;
+
+               Analyze (N);
+            end if;
+         end Precondition;
+
          ------------------
          -- Preelaborate --
          ------------------
@@ -9172,7 +9798,7 @@ package body Sem_Prag is
                --  described in "Handling of Default and Per-Object
                --  Expressions" in sem.ads.
 
-               Analyze_Per_Use_Expression (Arg, Standard_Integer);
+               Preanalyze_Spec_Expression (Arg, Standard_Integer);
 
                if not Is_Static_Expression (Arg) then
                   Check_Restriction (Static_Priorities, Arg);
@@ -9339,7 +9965,7 @@ package body Sem_Prag is
 
          --  pragma Profile (profile_IDENTIFIER);
 
-         --  profile_IDENTIFIER => Protected | Ravenscar
+         --  profile_IDENTIFIER => Restricted | Ravenscar
 
          when Pragma_Profile =>
             Ada_2005_Pragma;
@@ -9353,7 +9979,8 @@ package body Sem_Prag is
                if Chars (Argx) = Name_Ravenscar then
                   Set_Ravenscar_Profile (N);
                elsif Chars (Argx) = Name_Restricted then
-                  Set_Profile_Restrictions (Restricted, N, Warn => False);
+                  Set_Profile_Restrictions
+                    (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
                else
                   Error_Pragma_Arg ("& is not a valid profile", Argx);
                end if;
@@ -9365,7 +9992,7 @@ package body Sem_Prag is
 
          --  pragma Profile_Warnings (profile_IDENTIFIER);
 
-         --  profile_IDENTIFIER => Protected | Ravenscar
+         --  profile_IDENTIFIER => Restricted | Ravenscar
 
          when Pragma_Profile_Warnings =>
             GNAT_Pragma;
@@ -9699,6 +10326,55 @@ package body Sem_Prag is
             end if;
          end;
 
+         -----------------------
+         -- Relative_Deadline --
+         -----------------------
+
+         --  pragma Relative_Deadline (time_span_EXPRESSION);
+
+         when Pragma_Relative_Deadline => Relative_Deadline : declare
+            P   : constant Node_Id := Parent (N);
+            Arg : Node_Id;
+
+         begin
+            Ada_2005_Pragma;
+            Check_No_Identifiers;
+            Check_Arg_Count (1);
+
+            Arg := Expression (Arg1);
+
+            --  The expression must be analyzed in the special manner described
+            --  in "Handling of Default and Per-Object Expressions" in sem.ads.
+
+            Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
+
+            --  Subprogram case
+
+            if Nkind (P) = N_Subprogram_Body then
+               Check_In_Main_Program;
+
+            --  Tasks
+
+            elsif Nkind (P) = N_Task_Definition then
+               null;
+
+            --  Anything else is incorrect
+
+            else
+               Pragma_Misplaced;
+            end if;
+
+            if Has_Relative_Deadline_Pragma (P) then
+               Error_Pragma ("duplicate pragma% not allowed");
+            else
+               Set_Has_Relative_Deadline_Pragma (P, True);
+
+               if Nkind (P) = N_Task_Definition then
+                  Record_Rep_Item (Defining_Identifier (Parent (P)), N);
+               end if;
+            end if;
+         end Relative_Deadline;
+
          ---------------------------
          -- Remote_Call_Interface --
          ---------------------------
@@ -9799,7 +10475,8 @@ package body Sem_Prag is
             GNAT_Pragma;
             Check_Arg_Count (0);
             Check_Valid_Configuration_Pragma;
-            Set_Profile_Restrictions (Restricted, N, Warn => False);
+            Set_Profile_Restrictions
+              (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
 
             if Warn_On_Obsolescent_Feature then
                Error_Msg_N
@@ -9819,7 +10496,8 @@ package body Sem_Prag is
          --  | restriction_parameter_IDENTIFIER => EXPRESSION
 
          when Pragma_Restrictions =>
-            Process_Restrictions_Or_Restriction_Warnings (Warn => False);
+            Process_Restrictions_Or_Restriction_Warnings
+              (Warn => Treat_Restrictions_As_Warnings);
 
          --------------------------
          -- Restriction_Warnings --
@@ -9832,6 +10510,7 @@ package body Sem_Prag is
          --  | restriction_parameter_IDENTIFIER => EXPRESSION
 
          when Pragma_Restriction_Warnings =>
+            GNAT_Pragma;
             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
 
          ----------------
@@ -10025,13 +10704,11 @@ package body Sem_Prag is
             Check_No_Identifiers;
             Check_Arg_Count (1);
 
-            --  The expression must be analyzed in the special manner
-            --  described in "Handling of Default Expressions" in sem.ads.
-
-            --  Set In_Default_Expression for per-object case ???
+            --  The expression must be analyzed in the special manner described
+            --  in "Handling of Default Expressions" in sem.ads.
 
             Arg := Expression (Arg1);
-            Analyze_Per_Use_Expression (Arg, Any_Integer);
+            Preanalyze_Spec_Expression (Arg, Any_Integer);
 
             if not Is_Static_Expression (Arg) then
                Check_Restriction (Static_Storage_Size, Arg);
@@ -10117,7 +10794,7 @@ package body Sem_Prag is
                end if;
             end Check_OK_Stream_Convert_Function;
 
-         --  Start of procecessing for Stream_Convert
+         --  Start of processing for Stream_Convert
 
          begin
             GNAT_Pragma;
@@ -10137,24 +10814,35 @@ package body Sem_Prag is
                Write : constant Entity_Id := Entity (Expression (Arg3));
 
             begin
-               if Etype (Typ) = Any_Type
-                    or else
-                  Etype (Read) = Any_Type
+               Check_First_Subtype (Arg1);
+
+               --  Check for too early or too late. Note that we don't enforce
+               --  the rule about primitive operations in this case, since, as
+               --  is the case for explicit stream attributes themselves, these
+               --  restrictions are not appropriate. Note that the chaining of
+               --  the pragma by Rep_Item_Too_Late is actually the critical
+               --  processing done for this pragma.
+
+               if Rep_Item_Too_Early (Typ, N)
                     or else
-                  Etype (Write) = Any_Type
+                  Rep_Item_Too_Late (Typ, N, FOnly => True)
                then
                   return;
                end if;
 
-               Check_First_Subtype (Arg1);
+               --  Return if previous error
 
-               if Rep_Item_Too_Early (Typ, N)
+               if Etype (Typ) = Any_Type
                     or else
-                  Rep_Item_Too_Late (Typ, N)
+                  Etype (Read) = Any_Type
+                    or else
+                  Etype (Write) = Any_Type
                then
                   return;
                end if;
 
+               --  Error checks
+
                if Underlying_Type (Etype (Read)) /= Typ then
                   Error_Pragma_Arg
                     ("incorrect return type for function&", Arg2);
@@ -10397,6 +11085,7 @@ package body Sem_Prag is
          --  or the identifier GCC, no other identifiers are acceptable.
 
          when Pragma_System_Name =>
+            GNAT_Pragma;
             Check_No_Identifiers;
             Check_Arg_Count (1);
             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
@@ -10477,8 +11166,6 @@ package body Sem_Prag is
          --  pragma Task_Name (string_EXPRESSION);
 
          when Pragma_Task_Name => Task_Name : declare
-         --  pragma Priority (EXPRESSION);
-
             P   : constant Node_Id := Parent (N);
             Arg : Node_Id;
 
@@ -10552,6 +11239,42 @@ package body Sem_Prag is
             end if;
          end Task_Storage;
 
+         --------------------------
+         -- Thread_Local_Storage --
+         --------------------------
+
+         --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
+
+         when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
+            Id : Node_Id;
+            E  : Entity_Id;
+
+         begin
+            GNAT_Pragma;
+            Check_Arg_Count (1);
+            Check_Optional_Identifier (Arg1, Name_Entity);
+            Check_Arg_Is_Local_Name (Arg1);
+
+            Id := Expression (Arg1);
+            Analyze (Id);
+
+            if not Is_Entity_Name (Id)
+              or else Ekind (Entity (Id)) /= E_Variable
+            then
+               Error_Pragma_Arg ("local variable name required", Arg1);
+            end if;
+
+            E := Entity (Id);
+
+            if Rep_Item_Too_Early (E, N)
+              or else Rep_Item_Too_Late (E, N)
+            then
+               raise Pragma_Exit;
+            end if;
+
+            Set_Has_Pragma_Thread_Local_Storage (E);
+         end Thread_Local_Storage;
+
          ----------------
          -- Time_Slice --
          ----------------
@@ -10647,7 +11370,7 @@ package body Sem_Prag is
             Variant : Node_Id;
 
          begin
-            GNAT_Pragma;
+            Ada_2005_Pragma;
             Check_No_Identifiers;
             Check_Arg_Count (1);
             Check_Arg_Is_Local_Name (Arg1);
@@ -11014,7 +11737,7 @@ package body Sem_Prag is
          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
 
          when Pragma_Unsuppress =>
-            GNAT_Pragma;
+            Ada_2005_Pragma;
             Process_Suppress_Unsuppress (False);
 
          -------------------
@@ -11338,6 +12061,7 @@ package body Sem_Prag is
          --  pragma Wide_Character_Encoding (IDENTIFIER);
 
          when Pragma_Wide_Character_Encoding =>
+            GNAT_Pragma;
 
             --  Nothing to do, handled in parser. Note that we do not enforce
             --  configuration pragma placement, this pragma can appear at any
@@ -11361,6 +12085,39 @@ package body Sem_Prag is
       when Pragma_Exit => null;
    end Analyze_Pragma;
 
+   -------------------
+   -- Check_Enabled --
+   -------------------
+
+   function Check_Enabled (Nam : Name_Id) return Boolean is
+      PP : Node_Id;
+
+   begin
+      PP := Opt.Check_Policy_List;
+      loop
+         if No (PP) then
+            return Assertions_Enabled;
+
+         elsif
+           Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
+         then
+            case
+              Chars (Expression (Last (Pragma_Argument_Associations (PP))))
+            is
+            when Name_On | Name_Check =>
+               return True;
+            when Name_Off | Name_Ignore =>
+               return False;
+            when others =>
+               raise Program_Error;
+            end case;
+
+         else
+            PP := Next_Pragma (PP);
+         end if;
+      end loop;
+   end Check_Enabled;
+
    ---------------------------------
    -- Delay_Config_Pragma_Analyze --
    ---------------------------------
@@ -11396,6 +12153,28 @@ package body Sem_Prag is
       return Result;
    end Get_Base_Subprogram;
 
+   --------------------
+   -- Get_Pragma_Arg --
+   --------------------
+
+   function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
+   begin
+      if Nkind (Arg) = N_Pragma_Argument_Association then
+         return Expression (Arg);
+      else
+         return Arg;
+      end if;
+   end Get_Pragma_Arg;
+
+   ----------------
+   -- Initialize --
+   ----------------
+
+   procedure Initialize is
+   begin
+      Externals.Init;
+   end Initialize;
+
    -----------------------------
    -- Is_Config_Static_String --
    -----------------------------
@@ -11448,7 +12227,7 @@ package body Sem_Prag is
          return True;
       end Add_Config_Static_String;
 
-   --  Start of prorcessing for Is_Config_Static_String
+   --  Start of processing for Is_Config_Static_String
 
    begin
 
@@ -11463,11 +12242,14 @@ package body Sem_Prag is
    --  This function makes use of the following static table which indicates
    --  whether a given pragma is significant. A value of -1 in this table
    --  indicates that the reference is significant. A value of zero indicates
-   --  than appearence as any argument is insignificant, a positive value
-   --  indicates that appearence in that parameter position is significant.
+   --  than appearance as any argument is insignificant, a positive value
+   --  indicates that appearance in that parameter position is significant.
 
-   Sig_Flags : constant array (Pragma_Id) of Int :=
+   --  A value of 99 flags a special case requiring a special check (this is
+   --  used for cases not covered by this standard encoding, e.g. pragma Check
+   --  where the first argument is not significant, but the others are).
 
+   Sig_Flags : constant array (Pragma_Id) of Int :=
      (Pragma_AST_Entry                     => -1,
       Pragma_Abort_Defer                   => -1,
       Pragma_Ada_83                        => -1,
@@ -11478,11 +12260,14 @@ package body Sem_Prag is
       Pragma_Annotate                      => -1,
       Pragma_Assert                        => -1,
       Pragma_Assertion_Policy              =>  0,
+      Pragma_Assume_No_Invalid_Values      =>  0,
       Pragma_Asynchronous                  => -1,
       Pragma_Atomic                        =>  0,
       Pragma_Atomic_Components             =>  0,
       Pragma_Attach_Handler                => -1,
+      Pragma_Check                         => 99,
       Pragma_Check_Name                    =>  0,
+      Pragma_Check_Policy                  =>  0,
       Pragma_CIL_Constructor               => -1,
       Pragma_CPP_Class                     =>  0,
       Pragma_CPP_Constructor               =>  0,
@@ -11574,6 +12359,8 @@ package body Sem_Prag is
       Pragma_Preelaborable_Initialization  => -1,
       Pragma_Polling                       => -1,
       Pragma_Persistent_BSS                =>  0,
+      Pragma_Postcondition                 => -1,
+      Pragma_Precondition                  => -1,
       Pragma_Preelaborate                  => -1,
       Pragma_Preelaborate_05               => -1,
       Pragma_Priority                      => -1,
@@ -11587,6 +12374,7 @@ package body Sem_Prag is
       Pragma_Pure_Function                 => -1,
       Pragma_Queuing_Policy                => -1,
       Pragma_Ravenscar                     => -1,
+      Pragma_Relative_Deadline             => -1,
       Pragma_Remote_Call_Interface         => -1,
       Pragma_Remote_Types                  => -1,
       Pragma_Restricted_Run_Time           => -1,
@@ -11615,6 +12403,7 @@ package body Sem_Prag is
       Pragma_Task_Info                     => -1,
       Pragma_Task_Name                     => -1,
       Pragma_Task_Storage                  =>  0,
+      Pragma_Thread_Local_Storage          =>  0,
       Pragma_Time_Slice                    => -1,
       Pragma_Title                         => -1,
       Pragma_Unchecked_Union               =>  0,
@@ -11636,9 +12425,10 @@ package body Sem_Prag is
       Unknown_Pragma                       =>  0);
 
    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
-      P : Node_Id;
-      C : Int;
-      A : Node_Id;
+      Id : Pragma_Id;
+      P  : Node_Id;
+      C  : Int;
+      A  : Node_Id;
 
    begin
       P := Parent (N);
@@ -11647,7 +12437,8 @@ package body Sem_Prag is
          return False;
 
       else
-         C := Sig_Flags (Get_Pragma_Id (Parent (P)));
+         Id := Get_Pragma_Id (Parent (P));
+         C := Sig_Flags (Id);
 
          case C is
             when -1 =>
@@ -11656,6 +12447,21 @@ package body Sem_Prag is
             when 0 =>
                return True;
 
+            when 99 =>
+               case Id is
+
+                  --  For pragma Check, the first argument is not significant,
+                  --  the second and the third (if present) arguments are
+                  --  significant.
+
+                  when Pragma_Check =>
+                     return
+                       P = First (Pragma_Argument_Associations (Parent (P)));
+
+                  when others =>
+                     raise Program_Error;
+               end case;
+
             when others =>
                A := First (Pragma_Argument_Associations (Parent (P)));
                for J in 1 .. C - 1 loop
@@ -11666,7 +12472,7 @@ package body Sem_Prag is
                   Next (A);
                end loop;
 
-               return A = P;
+               return A = P; -- is this wrong way round ???
          end case;
       end if;
    end Is_Non_Significant_Pragma_Reference;
@@ -11920,4 +12726,5 @@ package body Sem_Prag is
          Set_Entity (Pref, Scop);
       end if;
    end Set_Unit_Name;
+
 end Sem_Prag;