This is the mail archive of the gcc-bugs@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]

ada/4484: Ada: Dead store elimination and scalar "out" parameters



>Number:         4484
>Category:       ada
>Synopsis:       Dead store elimination and scalar "out" parameters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 05 12:06:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Florian Weimer
>Release:        3.1 20011005 (experimental)
>Organization:
>Environment:
System: Linux deneb 2.4.7 #3 Sat Jul 21 09:35:45 CEST 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/opt/gcc-3
>Description:

Under certain circumstances, GNAT assumes that it can optimize away an
assignment to an "out" parameter because of subsequent assignments to
this parameter, although there is a code path without further assignments.

This happens only with scalar values.  The defect does only affect
pass-by-copy types, and due to the different parameter passing mechanism
of access types, they aren't affected either.  If you don't believe that
this GNAT behavior is a wrong, have a look at RM 6.4.1(17): Parameters are
assigned back only after normal completion.  In the case of exceptions,
we have abnormal completion according to RM 7.6.1(2), which means that
the assignment does not happen.

This is a resubmission of ACT bug report 7830-004.  Although the
submitter has managed to trigger this defect in actual code (and it is
quite difficult to track down), he agrees with ACT that a fix should
have very low priority.

>How-To-Repeat:

The following program should print "12", but it doesn't.

If you look at the generated assembler code (for example, on the x86
platform, Solaris/SPARC is affected, too), you will notice that the
statement "Out_Value := 12;" has been optimized away if the code is
compiled with "gnatmake -O2 out_test.adb" ("-O2" is important).  But as
External_Proc raises an exception, no assignment to Out_Value takes
place as a side effect of the subprogram call, so this optimization
is incorrect.

with Ada.Text_IO;
procedure Out_Test is

   procedure External_Proc (V : out Integer) is
   begin
      raise Constraint_Error;
   end External_Proc;

   procedure Do_Test (Out_Value : out Integer) is
   begin
      Out_Value := 12;
      External_Proc (Out_Value);
   exception
      when Constraint_Error =>
         null;
   end Do_Test;

   Out_Value : Integer := 11;

begin
   Do_Test (Out_Value);
   Ada.Text_IO.Put_Line (Integer'Image (Out_Value));
end Out_Test;

>Fix:
You can work around this problem by inserting a pragma Inspection_Point,
in this case before the call to External_Proc.
>Release-Note:
>Audit-Trail:
>Unformatted:


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