public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: ada/4851: GNAT crashs on certain argument lines
@ 2001-11-01  3:37 Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2001-11-01  3:37 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR ada/4851; it has been noted by GNATS.

From: Florian Weimer <fw@deneb.enyo.de>
To: dstarner98@aasaa.ofe.org
Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: ada/4851: GNAT crashs on certain argument lines
Date: Sun, 11 Nov 2001 17:56:52 +0100

 dstarner98@aasaa.ofe.org writes:
 
 > gnatmake -gnatwa -gnatwu -gnatwl -gnatwc -gnatf -gnato -gnatm40 -gnatG -gnatD -fprofile-arcs -ftest-coverage -O2 -gnata -gnatiw -gnatW8 -g -fprofile-arcs -ftest-coverage -gnaty3acefiklM100nprst   program.adb
 > ~/Code/Ngeadal/source/bug $ ./file
 > Exception name: STORAGE_ERROR
 > Message: stack overflow (or erroneous memory access)
 
 Here's the fix.
 
 The problem is caused by the fact that a call to an instantiation of
 Generic_Position can change T.Table as a side effect (if a
 reallocation is necessary due to table growth).  Since the prefix and
 the indexed_compound in the assignment statements below are evaluated
 in arbitrary order, the prefix might be the old value of T.Table,
 leading to erroneous execution and the erratic behavior observed by
 David Starner.
 
 The old comment suggests that Generic_Position once was a procedure.
 I wonder who changed it and why. ;-) (The bug is present in the GNAT
 3.13p sources as well, but it might not show up because of code
 generation differences.)
 
 2001-11-11  Florian Weimer  <fw@deneb.enyo.de>
 
 	* make.adb (Add_Switch): Make Generic_Position a procedure.
 	The function approach did not work well because of a side
 	effect (the function call could reallocate the table which was
 	being indexed using its result).
 
 
 Index: make.adb
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/ada/make.adb,v
 retrieving revision 1.2
 diff -c -p -3 -r1.2 make.adb
 *** make.adb	2001/10/11 01:02:02	1.2
 --- make.adb	2001/11/11 16:02:20
 *************** package body Make is
 *** 526,580 ****
      is
         generic
            with package T is new Table.Table (<>);
 !       function Generic_Position return Integer;
 !       --  Generic procedure that adds S at the end or beginning of T depending
 !       --  of the value of the boolean Append_Switch.
   
         ----------------------
         -- Generic_Position --
         ----------------------
   
 !       function Generic_Position return Integer is
         begin
            T.Increment_Last;
   
            if Append_Switch then
 !             return Integer (T.Last);
            else
               for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
                  T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
               end loop;
   
 !             return Integer (T.First);
            end if;
         end Generic_Position;
   
 !       function Gcc_Switches_Pos    is new Generic_Position (Gcc_Switches);
 !       function Binder_Switches_Pos is new Generic_Position (Binder_Switches);
 !       function Linker_Switches_Pos is new Generic_Position (Linker_Switches);
   
 !       function Saved_Gcc_Switches_Pos is new
           Generic_Position (Saved_Gcc_Switches);
   
 !       function Saved_Binder_Switches_Pos is new
           Generic_Position (Saved_Binder_Switches);
   
 !       function Saved_Linker_Switches_Pos is new
           Generic_Position (Saved_Linker_Switches);
   
      --  Start of processing for Add_Switch
   
      begin
         if And_Save then
            case Program is
               when Compiler =>
 !                Saved_Gcc_Switches.Table (Saved_Gcc_Switches_Pos) := S;
   
               when Binder   =>
 !                Saved_Binder_Switches.Table (Saved_Binder_Switches_Pos) := S;
   
               when Linker   =>
 !                Saved_Linker_Switches.Table (Saved_Linker_Switches_Pos) := S;
   
               when None =>
                  raise Program_Error;
 --- 526,586 ----
      is
         generic
            with package T is new Table.Table (<>);
 !       procedure Generic_Position (New_Position : out Integer);
 !       --  Generic procedure that chooses a position for S in T at the
 !       --  beginning or the end, depending on the boolean Append_Switch.
   
 + 
         ----------------------
         -- Generic_Position --
         ----------------------
   
 !       procedure  Generic_Position (New_Position : out Integer) is
         begin
            T.Increment_Last;
   
            if Append_Switch then
 !             New_Position := Integer (T.Last);
            else
               for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
                  T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
               end loop;
   
 !             New_Position := Integer (T.First);
            end if;
         end Generic_Position;
   
 !       procedure Gcc_Switches_Pos    is new Generic_Position (Gcc_Switches);
 !       procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
 !       procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
   
 !       procedure Saved_Gcc_Switches_Pos is new
           Generic_Position (Saved_Gcc_Switches);
   
 !       procedure Saved_Binder_Switches_Pos is new
           Generic_Position (Saved_Binder_Switches);
   
 !       procedure Saved_Linker_Switches_Pos is new
           Generic_Position (Saved_Linker_Switches);
   
 +       New_Position : Integer;
 + 
      --  Start of processing for Add_Switch
   
      begin
         if And_Save then
            case Program is
               when Compiler =>
 !                Saved_Gcc_Switches_Pos (New_Position);
 !                Saved_Gcc_Switches.Table (New_Position) := S;
   
               when Binder   =>
 !                Saved_Binder_Switches_Pos (New_Position);
 !                Saved_Binder_Switches.Table (New_Position) := S;
   
               when Linker   =>
 !                Saved_Linker_Switches_Pos (New_Position);
 !                Saved_Linker_Switches.Table (New_Position) := S;
   
               when None =>
                  raise Program_Error;
 *************** package body Make is
 *** 583,595 ****
         else
            case Program is
               when Compiler =>
 !                Gcc_Switches.Table (Gcc_Switches_Pos) := S;
   
               when Binder   =>
 !                Binder_Switches.Table (Binder_Switches_Pos) := S;
   
               when Linker   =>
 !                Linker_Switches.Table (Linker_Switches_Pos) := S;
   
               when None =>
                  raise Program_Error;
 --- 589,604 ----
         else
            case Program is
               when Compiler =>
 !                Gcc_Switches_Pos (New_Position);
 !                Gcc_Switches.Table (New_Position) := S;
   
               when Binder   =>
 !                Binder_Switches_Pos (New_Position);
 !                Binder_Switches.Table (New_Position) := S;
   
               when Linker   =>
 !                Linker_Switches_Pos (New_Position);
 !                Linker_Switches.Table (New_Position) := S;
   
               when None =>
                  raise Program_Error;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ada/4851: GNAT crashs on certain argument lines
@ 2001-12-22  4:06 Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2001-12-22  4:06 UTC (permalink / raw)
  To: fw; +Cc: gcc-prs

The following reply was made to PR ada/4851; it has been noted by GNATS.

From: Florian Weimer <fw@deneb.enyo.de>
To: Geert Bosch <bosch@gnat.com>
Cc: gcc-gnats@gcc.gnu.org,  gcc-patches@gcc.gnu.org
Subject: Re: ada/4851: GNAT crashs on certain argument lines
Date: Sat, 22 Dec 2001 13:25:08 +0100

 Geert Bosch <bosch@gnat.com> writes:
 
 > Your patch is OK. I have regression-tested it against the ACT test-suite
 > and it passes fine, as expected. I'd only suggest a one-word comment
 > improvement:
 >
 > <       --  Generic procedure that chooses a position for S in T at the
 
 > >       --  Generic procedure that allocates a position for S in T at the
 
 I've committed the following change, incorporating your suggestion.
 
 2001-12-22  Florian Weimer  <fw@deneb.enyo.de>
 
 	* make.adb (Add_Switch): Make Generic_Position a procedure.  The
 	function approach did not work well because of a side effect (the
 	function call could reallocate the table which was being indexed
 	using its result). Fixes ada/4851.
 
 Index: make.adb
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/ada/make.adb,v
 retrieving revision 1.9
 diff -c -3 -r1.9 make.adb
 *** make.adb	2001/12/20 06:22:41	1.9
 --- make.adb	2001/12/22 11:53:26
 ***************
 *** 554,608 ****
      is
         generic
            with package T is new Table.Table (<>);
 !       function Generic_Position return Integer;
 !       --  Generic procedure that adds S at the end or beginning of T depending
 !       --  of the value of the boolean Append_Switch.
   
         ----------------------
         -- Generic_Position --
         ----------------------
   
 !       function Generic_Position return Integer is
         begin
            T.Increment_Last;
   
            if Append_Switch then
 !             return Integer (T.Last);
            else
               for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
                  T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
               end loop;
   
 !             return Integer (T.First);
            end if;
         end Generic_Position;
   
 !       function Gcc_Switches_Pos    is new Generic_Position (Gcc_Switches);
 !       function Binder_Switches_Pos is new Generic_Position (Binder_Switches);
 !       function Linker_Switches_Pos is new Generic_Position (Linker_Switches);
   
 !       function Saved_Gcc_Switches_Pos is new
           Generic_Position (Saved_Gcc_Switches);
   
 !       function Saved_Binder_Switches_Pos is new
           Generic_Position (Saved_Binder_Switches);
   
 !       function Saved_Linker_Switches_Pos is new
           Generic_Position (Saved_Linker_Switches);
   
      --  Start of processing for Add_Switch
   
      begin
         if And_Save then
            case Program is
               when Compiler =>
 !                Saved_Gcc_Switches.Table (Saved_Gcc_Switches_Pos) := S;
   
               when Binder   =>
 !                Saved_Binder_Switches.Table (Saved_Binder_Switches_Pos) := S;
   
               when Linker   =>
 !                Saved_Linker_Switches.Table (Saved_Linker_Switches_Pos) := S;
   
               when None =>
                  raise Program_Error;
 --- 554,613 ----
      is
         generic
            with package T is new Table.Table (<>);
 !       procedure Generic_Position (New_Position : out Integer);
 !       --  Generic procedure that allocates a position for S in T at the
 !       --  beginning or the end, depending on the boolean Append_Switch.
   
         ----------------------
         -- Generic_Position --
         ----------------------
   
 !       procedure  Generic_Position (New_Position : out Integer) is
         begin
            T.Increment_Last;
   
            if Append_Switch then
 !             New_Position := Integer (T.Last);
            else
               for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
                  T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
               end loop;
   
 !             New_Position := Integer (T.First);
            end if;
         end Generic_Position;
   
 !       procedure Gcc_Switches_Pos    is new Generic_Position (Gcc_Switches);
 !       procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
 !       procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
   
 !       procedure Saved_Gcc_Switches_Pos is new
           Generic_Position (Saved_Gcc_Switches);
   
 !       procedure Saved_Binder_Switches_Pos is new
           Generic_Position (Saved_Binder_Switches);
   
 !       procedure Saved_Linker_Switches_Pos is new
           Generic_Position (Saved_Linker_Switches);
   
 +       New_Position : Integer;
 + 
      --  Start of processing for Add_Switch
   
      begin
         if And_Save then
            case Program is
               when Compiler =>
 !                Saved_Gcc_Switches_Pos (New_Position);
 !                Saved_Gcc_Switches.Table (New_Position) := S;
   
               when Binder   =>
 !                Saved_Binder_Switches_Pos (New_Position);
 !                Saved_Binder_Switches.Table (New_Position) := S;
   
               when Linker   =>
 !                Saved_Linker_Switches_Pos (New_Position);
 !                Saved_Linker_Switches.Table (New_Position) := S;
   
               when None =>
                  raise Program_Error;
 ***************
 *** 611,623 ****
         else
            case Program is
               when Compiler =>
 !                Gcc_Switches.Table (Gcc_Switches_Pos) := S;
   
               when Binder   =>
 !                Binder_Switches.Table (Binder_Switches_Pos) := S;
   
               when Linker   =>
 !                Linker_Switches.Table (Linker_Switches_Pos) := S;
   
               when None =>
                  raise Program_Error;
 --- 616,631 ----
         else
            case Program is
               when Compiler =>
 !                Gcc_Switches_Pos (New_Position);
 !                Gcc_Switches.Table (New_Position) := S;
   
               when Binder   =>
 !                Binder_Switches_Pos (New_Position);
 !                Binder_Switches.Table (New_Position) := S;
   
               when Linker   =>
 !                Linker_Switches_Pos (New_Position);
 !                Linker_Switches.Table (New_Position) := S;
   
               when None =>
                  raise Program_Error;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ada/4851: GNAT crashs on certain argument lines
@ 2001-12-22  4:03 fw
  0 siblings, 0 replies; 5+ messages in thread
From: fw @ 2001-12-22  4:03 UTC (permalink / raw)
  To: dstarner98, fw, gcc-bugs, gcc-prs, nobody

Synopsis: GNAT crashs on certain argument lines

Responsible-Changed-From-To: unassigned->fw
Responsible-Changed-By: fw
Responsible-Changed-When: Sat Dec 22 04:03:25 2001
Responsible-Changed-Why:
    Bug analyzed (prior to GNATS write access).
State-Changed-From-To: open->closed
State-Changed-By: fw
State-Changed-When: Sat Dec 22 04:03:25 2001
State-Changed-Why:
    Fixed by change committed on 2001-12-21.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4851


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ada/4851: GNAT crashs on certain argument lines
@ 2001-12-14 11:26 Geert Bosch
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Bosch @ 2001-12-14 11:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR ada/4851; it has been noted by GNATS.

From: Geert Bosch <bosch@gnat.com>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: ada/4851: GNAT crashs on certain argument lines
Date: Fri, 14 Dec 2001 14:18:06 -0500

 Hi Florian,
 
 You wrote:
 > The old comment suggests that Generic_Position once was a procedure.
 > I wonder who changed it and why. ;-) (The bug is present in the GNAT
 > 3.13p sources as well, but it might not show up because of code
 > generation differences.)
 This code was introduced in 1999 and always had the bug you mention,
 and always was a function rather than a procedure.
 
 > 2001-11-11  Florian Weimer  <fw@deneb.enyo.de>
 >
 > 	* make.adb (Add_Switch): Make Generic_Position a procedure.
 > 	The function approach did not work well because of a side
 > 	effect (the function call could reallocate the table which was
 > 	being indexed using its result).
 
 Your patch is OK. I have regression-tested it against the ACT test-suite
 and it passes fine, as expected. I'd only suggest a one-word comment 
 improvement:
 
 <       --  Generic procedure that chooses a position for S in T at the
 --
  >       --  Generic procedure that allocates a position for S in T at the
 
 This better describes what the procedure does.
 
 Regards,
    -Geert
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ada/4851: GNAT crashs on certain argument lines
@ 2001-12-13 18:26 Geert Bosch
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Bosch @ 2001-12-13 18:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR ada/4851; it has been noted by GNATS.

From: Geert Bosch <bosch@gnat.com>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: dstarner98@aasaa.ofe.org, gcc-gnats@gcc.gnu.org,
	gcc-patches@gcc.gnu.org
Subject: Re: ada/4851: GNAT crashs on certain argument lines
Date: Thu, 13 Dec 2001 21:24:42 -0500

 On Sunday, November 11, 2001, at 11:56 , Florian Weimer wrote:
 > 2001-11-11  Florian Weimer  <fw@deneb.enyo.de>
 >
 > 	* make.adb (Add_Switch): Make Generic_Position a procedure.
 > 	The function approach did not work well because of a side
 > 	effect (the function call could reallocate the table which was
 > 	being indexed using its result).
 
 My excuses for not having noticed this patch. Please copy me explicitly
 if you want to be sure I see the message.
 
 I'll review it first thing tomorrow.
 
    -Geert
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-12-22 12:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-01  3:37 ada/4851: GNAT crashs on certain argument lines Florian Weimer
2001-12-13 18:26 Geert Bosch
2001-12-14 11:26 Geert Bosch
2001-12-22  4:03 fw
2001-12-22  4:06 Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).