This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Aliasing checks on subprograms may cause side effects


Compiling with aliasing checks on subprograms parameters (-gnateA),
if the actual of a subprogram parameter is a function call the
compiler may generate a runtime check that invokes the function
more than once.

After this patch the following test compiles and executes well.

with Ada.Text_IO; use Ada.Text_IO;
procedure Do_Test is
   Call_Counter : Natural := 0;

   function Get_Value return String is
   begin
      Call_Counter := Call_Counter + 1;

      if Call_Counter = 1 then
         return "OK";
      else
         return "Failure";
      end if;
   end Get_Value;

   procedure Do_Test (S1 : String; S2 : in out String) is
   begin
      Put_Line (S1);
   end Do_Test;
 
   Dummy : String := ":";
begin
   Do_Test (Get_Value, Dummy);
end;

Command: gnatmake -gnateA do_test.adb; ./do_test
 Output: OK

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

2017-01-23  Javier Miranda  <miranda@adacore.com>

	* checks.adb (Apply_Parameter_Aliasing_Checks):
	Remove side effects of the actuals before generating the overlap
	check.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]