This patch implements the required incompatible change in Ada 2012 that makes overlap of elementary parameters passed as OUT or IN OUT an error (rather than a warning situation). It also implements the debug flag -gnatd.E that converts this back to a warning.
The following program compiled in Ada 2012 mode gives: 1. with Text_IO; use Text_IO; 2. procedure OverlapWarn is 3. procedure OW (a, b : out Integer) is 4. begin 5. A := 3; 6. B := 3; 7. end; 8. X : Integer; 9. begin 10. OW (X, X); | >>> writable actual for "a" overlaps with actual for "b" 11. Put_Line (X'Img); 12. end OverlapWarn; But if -gnatd.E is given in Ada 2012 mode, the error is a warning: 1. with Text_IO; use Text_IO; 2. procedure OverlapWarn is 3. procedure OW (a, b : out Integer) is 4. begin 5. A := 3; 6. B := 3; 7. end; 8. X : Integer; 9. begin 10. OW (X, X); | >>> warning: writable actual for "a" overlaps with actual for "b" 11. Put_Line (X'Img); 12. end OverlapWarn; And the program can be executed, and outputs 3 Tested on x86_64-pc-linux-gnu, committed on trunk 2013-10-14 Robert Dewar <de...@adacore.com> * debug.adb: Document -gnatd.E. * gnat1drv.adb (Adjust_Global_Switches): Set Error_To_Warning if -gnatd.E set. * opt.ads (Error_To_Warning): New switch. * osint.adb: Minor reformatting. * sem_warn.adb (Warn_On_Overlapping_Actuals): Overlap is error in some cases in Ada 2012 mode (unless Error_To_Warning) is set. * sem_warn.ads (Warn_On_Overlapping_Actuals): Document error in Ada 2012 mode.
Index: debug.adb =================================================================== --- debug.adb (revision 203524) +++ debug.adb (working copy) @@ -122,7 +122,7 @@ -- d.B -- d.C Generate concatenation call, do not generate inline code -- d.D SPARK strict mode - -- d.E + -- d.E Turn selected errors into warnings -- d.F SPARK mode -- d.G Frame condition mode for gnat2why -- d.H @@ -581,22 +581,26 @@ -- d.w This flag turns off the scanning of loops to detect possible -- infinite loops. + -- d.x No exception handlers in generated code. This causes exception + -- handlers to be eliminated from the generated code. They are still + -- fully compiled and analyzed, they just get eliminated from the + -- code generation step. + -- d.A There seems to be a problem with ASIS if we activate the circuit -- for reading and writing the aspect specification hash table, so -- for now, this is controlled by the debug flag d.A. The hash table -- is only written and read if this flag is set. - -- d.x No exception handlers in generated code. This causes exception - -- handlers to be eliminated from the generated code. They are still - -- fully compiled and analyzed, they just get eliminated from the - -- code generation step. - -- d.C Generate call to System.Concat_n.Str_Concat_n routines in cases -- where we would normally generate inline concatenation code. -- d.D SPARK strict mode. Interpret compiler permissions as strictly as -- possible in SPARK mode. - -- + + -- d.E Turn selected errors into warnings. This debug switch causes a + -- specific set of error messages into warnings. Setting this switch + -- causes Opt.Error_To_Warning to be set to True. + -- d.F SPARK mode. Generate AST in a form suitable for formal -- verification, as well as additional cross reference information in -- ALI files to compute effects of subprograms. Note that ALI files Index: gnat1drv.adb =================================================================== --- gnat1drv.adb (revision 203521) +++ gnat1drv.adb (working copy) @@ -117,6 +117,13 @@ Relaxed_RM_Semantics := True; end if; + -- -gnatd.E sets Error_To_Warning mode, causing selected error messages + -- to be treated as warnings instead of errors. + + if Debug_Flag_Dot_EE then + Error_To_Warning := True; + end if; + -- Disable CodePeer_Mode in Check_Syntax, since we need front-end -- expansion. Index: sem_warn.adb =================================================================== --- sem_warn.adb (revision 203521) +++ sem_warn.adb (working copy) @@ -3410,13 +3410,27 @@ then null; - -- Here we may need to issue message + -- Here we may need to issue overlap message else Error_Msg_Warn := + + -- Overlap checking is an error only in Ada 2012. For + -- earlier versions of Ada, this is a warning. + Ada_Version < Ada_2012 - or else not Is_Elementary_Type (Etype (Form1)); + -- Overlap is only illegal in Ada 2012 in the case of + -- elementary types (passed by copy). For other types, + -- we always have a warning in all Ada versions. + + or else not Is_Elementary_Type (Etype (Form1)) + + -- Finally, debug flag -gnatd.E changes the error to a + -- warning even in Ada 2012 mode. + + or else Error_To_Warning; + declare Act : Node_Id; Form : Entity_Id; @@ -3457,23 +3471,28 @@ then if Act1 = First_Actual (N) then Error_Msg_FE - ("`IN OUT` prefix overlaps with " - & "actual for&?I?", Act1, Form); + ("<`IN OUT` prefix overlaps with " + & "actual for&", Act1, Form); else -- For greater clarity, give name of formal Error_Msg_Node_2 := Form; Error_Msg_FE - ("writable actual for & overlaps with " - & "actual for&?I?", Act1, Form); + ("<writable actual for & overlaps with " + & "actual for&", Act1, Form); end if; else + -- For greater clarity, give name of formal + Error_Msg_Node_2 := Form; + + -- This is one of the messages + Error_Msg_FE - ("writable actual for & overlaps with " - & "actual for&?I?", Act1, Form1); + ("<writable actual for & overlaps with " + & "actual for&", Act1, Form1); end if; end; end if; Index: sem_warn.ads =================================================================== --- sem_warn.ads (revision 203521) +++ sem_warn.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1999-2011, Free Software Foundation, Inc. -- +-- Copyright (C) 1999-2013, 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- -- @@ -198,7 +198,9 @@ procedure Warn_On_Overlapping_Actuals (Subp : Entity_Id; N : Node_Id); -- Called on a subprogram call. Checks whether an IN OUT actual that is -- not by-copy may overlap with another actual, thus leading to aliasing - -- in the body of the called subprogram. + -- in the body of the called subprogram. This is indeed a warning in Ada + -- versions prior to Ada 2012, but, unless Opt.Error_To_Warning is set by + -- use of debug flag -gnatd.E, this is illegal and generates an error. procedure Warn_On_Suspicious_Index (Name : Entity_Id; X : Node_Id); -- This is called after resolving an indexed component or a slice. Name Index: opt.ads =================================================================== --- opt.ads (revision 203536) +++ opt.ads (working copy) @@ -516,6 +516,13 @@ -- to make a single long message, and then this message is split up into -- multiple lines not exceeding the specified length. Set by -gnatj=nn. + Error_To_Warning : Boolean := False; + -- GNAT + -- If True, then certain error messages (e.g. parameter overlap messages + -- for procedure calls in Ada 2012 mode) are treated as warnings instead + -- of errors. Set by debug flag -gnatd.E. A search for Error_To_Warning + -- will identify affected messages. + Exception_Handler_Encountered : Boolean := False; -- GNAT -- This flag is set true if the parser encounters an exception handler. Index: osint.adb =================================================================== --- osint.adb (revision 203521) +++ osint.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2013, 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- -- @@ -1044,8 +1044,8 @@ procedure Fail (S : String) is begin - -- We use Output in case there is a special output set up. - -- In this case Set_Standard_Error will have no immediate effect. + -- We use Output in case there is a special output set up. In this case + -- Set_Standard_Error will have no immediate effect. Set_Standard_Error; Osint.Write_Program_Name;