public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/42140]  New: GNAT appears to misbehave with limited tagged types and possibly finalization
@ 2009-11-22  5:22 gcc at coreland dot ath dot cx
  2009-11-22  5:27 ` [Bug ada/42140] " gcc at coreland dot ath dot cx
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc at coreland dot ath dot cx @ 2009-11-22  5:22 UTC (permalink / raw)
  To: gcc-bugs

I'm working on a small project to create an abstraction over directories
and archives. I've managed to write some code that seems simple enough
(using tagged limited types) and even though the code appears to be valid,
it seems to either trigger bugs in the runtime (causing crashes on execution)
or fails to compile:

Both Debian GCC 4.3, GNAT GPL 2009 and FreeBSD GCC 4.4 fail with the following:

  pfseudo-archiver-directory.adb:24:41: wrong type for
return_subtype_indication
  pfseudo-archiver-directory.adb:46:35: wrong type for
return_subtype_indication

GCC SVN (r154285) fails to build with a strange error:

  arc_dir_003.adb:25:32: "_master" conflicts with declaration at line 21

The output of -gnatG shows this error to be apparently incorrect:

   error := false;
   B_1 : declare
      _master : constant integer := system__soft_links__current_master.all;
      A6bM : integer renames _master;
      type A6b is access all pfseudo__archiver__Tarchive_tC;
      R7b : A6b := pfseudo__archiver__directory.

The code is available here:

  http://git.coreland.ath.cx/gitweb.cgi?p=pfseudo/.git;a=summary
  $ git clone http://git.coreland.ath.cx/pfseudo/.git

Configure and build with:

  $ echo 'gcc'      > conf-adacomp
  $ echo 'gnatbind' > conf-adabind
  $ echo 'gnatlink' > conf-adalink
  $ make
  $ make tests

Here's another case from a prototype that causes a crash on GCC 4.4
but, ironically, gives every impression of compiling and running
on earlier versions (4.3, GPL 2009):

with Ada.Streams.Stream_IO;
with Ada.Finalization;

package Archiver is

  type Archiver_t is tagged limited private;
  type Archive_t  is tagged limited private;

  function Open_Archive
    (Archiver : in Archiver_t;
     Path     : in String) return Archive_t'Class;

  function Stream
    (Archive : in Archive_t)
      return Ada.Streams.Stream_IO.Stream_Access;

private
  package Stream_IO renames Ada.Streams.Stream_IO;

  type Archiver_t is tagged limited null record;

  type Archive_t is new Ada.Finalization.Limited_Controlled with record
    Name : access String;
    File : Stream_IO.File_Type;
  end record;

end Archiver;

package body Archiver is

  function Open_Archive
    (Archiver : in Archiver_t;
     Path     : in String) return Archive_t'Class
  is
    pragma Unreferenced (Archiver);
  begin
    -- This line causes a segmentation fault.
    return A : Archive_t'Class :=
Archive_t'(Ada.Finalization.Limited_Controlled with others => <>) do
      A.Name := new String'(Path);
      Stream_IO.Open
        (Name => A.Name.all,
         File => A.File,
         Mode => Stream_IO.In_File);
    end return;
  end Open_Archive;

  function Stream
    (Archive : in Archive_t)
      return Ada.Streams.Stream_IO.Stream_Access is
  begin
    return Stream_IO.Stream (Archive.File);
  end Stream;

end Archiver;

with Ada.Text_IO;
with Ada.Streams.Stream_IO;
with Archiver;

procedure Main is

  A : Archiver.Archiver_t;
  S : constant Ada.Streams.Stream_IO.Stream_Access := Archiver.Stream
(Archiver.Open_Archive (A, "file.zip"));
  X : Integer;

begin
  X := Integer'Input (S);

  Ada.Text_IO.Put_Line (Integer'Image (X));
end Main;


-- 
           Summary: GNAT appears to misbehave with limited tagged types and
                    possibly finalization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at coreland dot ath dot cx
  GCC host triplet: x86_64-portbld-freebsd7.2, i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140


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

* [Bug ada/42140] GNAT appears to misbehave with limited tagged types and possibly finalization
  2009-11-22  5:22 [Bug ada/42140] New: GNAT appears to misbehave with limited tagged types and possibly finalization gcc at coreland dot ath dot cx
@ 2009-11-22  5:27 ` gcc at coreland dot ath dot cx
  2009-11-22 16:41 ` gcc at coreland dot ath dot cx
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gcc at coreland dot ath dot cx @ 2009-11-22  5:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from gcc at coreland dot ath dot cx  2009-11-22 05:27 -------
By "causes a crash" above, I meant that the generated code crashes at
the highlighted line.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140


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

* [Bug ada/42140] GNAT appears to misbehave with limited tagged types and possibly finalization
  2009-11-22  5:22 [Bug ada/42140] New: GNAT appears to misbehave with limited tagged types and possibly finalization gcc at coreland dot ath dot cx
  2009-11-22  5:27 ` [Bug ada/42140] " gcc at coreland dot ath dot cx
@ 2009-11-22 16:41 ` gcc at coreland dot ath dot cx
  2009-11-22 17:02 ` john at johnnowak dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gcc at coreland dot ath dot cx @ 2009-11-22 16:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from gcc at coreland dot ath dot cx  2009-11-22 16:41 -------
A couple of people have commented on the anonymous access type
(claiming it causes the crash). Here's a version with it removed
and a gdb backtrace:

Program received signal SIGSEGV, Segmentation fault.
system.finalization_implementation.move_final_list (from=0x800a02040, to=0x0)
at s-finimp.adb:486
486     s-finimp.adb: No such file or directory.
        in s-finimp.adb
(gdb) bt
#0  system.finalization_implementation.move_final_list (from=0x800a02040,
to=0x0) at s-finimp.adb:486
#1  0x0000000000402cfb in archiver.open_archive (archiver=(), path=0x41fe18,
<open_archiveBIPalloc>=4324888, 
    <open_archiveBIPfinallist>=0x0, <open_archiveBIPaccess>=0x7fffffffe6d8) at
archiver.adb:9
#2  0x0000000000402e9f in main () at main.adb:9

Probably advisable to add an assertion in Move_Final_List
to ensure that 'To' is not null.

-- %< archiver.ads

with Ada.Finalization;
with Ada.Streams.Stream_IO;

package Archiver is

  type Archiver_t is tagged limited private;
  type Archive_t  is tagged limited private;

  function Open_Archive
    (Archiver : in Archiver_t;
     Path     : in String) return Archive_t'Class;

  function Stream
    (Archive : in Archive_t)
      return Ada.Streams.Stream_IO.Stream_Access;

private
  package Stream_IO renames Ada.Streams.Stream_IO;

  type Archiver_t is tagged limited null record;

  type Archive_t is new Ada.Finalization.Limited_Controlled with record
    File : Stream_IO.File_Type;
  end record;

end Archiver;

-- %< archiver.adb

package body Archiver is

  function Open_Archive
    (Archiver : in Archiver_t;
     Path     : in String) return Archive_t'Class
  is
    pragma Unreferenced (Archiver);
  begin
    return A : Archive_t'Class :=
Archive_t'(Ada.Finalization.Limited_Controlled with others => <>) do
      Stream_IO.Open
        (Name => Path,
         File => A.File,
         Mode => Stream_IO.In_File);
    end return;
  end Open_Archive;

  function Stream
    (Archive : in Archive_t)
      return Ada.Streams.Stream_IO.Stream_Access is
  begin
    return Stream_IO.Stream (Archive.File);
  end Stream;

end Archiver;

-- %< main.adb

with Ada.Text_IO;
with Ada.Streams.Stream_IO;
with Archiver;

procedure Main is

  A : Archiver.Archiver_t;
  S : constant Ada.Streams.Stream_IO.Stream_Access := Archiver.Stream
(Archiver.Open_Archive (A, "file.zip"));
  X : Integer;

begin
  X := Integer'Input (S);

  Ada.Text_IO.Put_Line (Integer'Image (X));
end Main;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140


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

* [Bug ada/42140] GNAT appears to misbehave with limited tagged types and possibly finalization
  2009-11-22  5:22 [Bug ada/42140] New: GNAT appears to misbehave with limited tagged types and possibly finalization gcc at coreland dot ath dot cx
  2009-11-22  5:27 ` [Bug ada/42140] " gcc at coreland dot ath dot cx
  2009-11-22 16:41 ` gcc at coreland dot ath dot cx
@ 2009-11-22 17:02 ` john at johnnowak dot com
  2009-11-22 17:11 ` gcc at coreland dot ath dot cx
  2009-11-22 18:37 ` gcc at coreland dot ath dot cx
  4 siblings, 0 replies; 6+ messages in thread
From: john at johnnowak dot com @ 2009-11-22 17:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from john at johnnowak dot com  2009-11-22 17:02 -------
Subject: Re:  GNAT appears to misbehave with limited tagged types and possibly
finalization

You know, your code would be a lot better if you didn't use anonymous  
access types. (:-))

On Nov 22, 2009, at 11:41 AM, gcc at coreland dot ath dot cx wrote:

>
>
> ------- Comment #2 from gcc at coreland dot ath dot cx  2009-11-22  
> 16:41 -------
> A couple of people have commented on the anonymous access type
> (claiming it causes the crash). Here's a version with it removed
> and a gdb backtrace:
>
> Program received signal SIGSEGV, Segmentation fault.
> system.finalization_implementation.move_final_list  
> (from=0x800a02040, to=0x0)
> at s-finimp.adb:486
> 486     s-finimp.adb: No such file or directory.
>        in s-finimp.adb
> (gdb) bt
> #0  system.finalization_implementation.move_final_list  
> (from=0x800a02040,
> to=0x0) at s-finimp.adb:486
> #1  0x0000000000402cfb in archiver.open_archive (archiver=(),  
> path=0x41fe18,
> <open_archiveBIPalloc>=4324888,
>    <open_archiveBIPfinallist>=0x0,  
> <open_archiveBIPaccess>=0x7fffffffe6d8) at
> archiver.adb:9
> #2  0x0000000000402e9f in main () at main.adb:9
>
> Probably advisable to add an assertion in Move_Final_List
> to ensure that 'To' is not null.
>
> -- %< archiver.ads
>
> with Ada.Finalization;
> with Ada.Streams.Stream_IO;
>
> package Archiver is
>
>  type Archiver_t is tagged limited private;
>  type Archive_t  is tagged limited private;
>
>  function Open_Archive
>    (Archiver : in Archiver_t;
>     Path     : in String) return Archive_t'Class;
>
>  function Stream
>    (Archive : in Archive_t)
>      return Ada.Streams.Stream_IO.Stream_Access;
>
> private
>  package Stream_IO renames Ada.Streams.Stream_IO;
>
>  type Archiver_t is tagged limited null record;
>
>  type Archive_t is new Ada.Finalization.Limited_Controlled with record
>    File : Stream_IO.File_Type;
>  end record;
>
> end Archiver;
>
> -- %< archiver.adb
>
> package body Archiver is
>
>  function Open_Archive
>    (Archiver : in Archiver_t;
>     Path     : in String) return Archive_t'Class
>  is
>    pragma Unreferenced (Archiver);
>  begin
>    return A : Archive_t'Class :=
> Archive_t'(Ada.Finalization.Limited_Controlled with others => <>) do
>      Stream_IO.Open
>        (Name => Path,
>         File => A.File,
>         Mode => Stream_IO.In_File);
>    end return;
>  end Open_Archive;
>
>  function Stream
>    (Archive : in Archive_t)
>      return Ada.Streams.Stream_IO.Stream_Access is
>  begin
>    return Stream_IO.Stream (Archive.File);
>  end Stream;
>
> end Archiver;
>
> -- %< main.adb
>
> with Ada.Text_IO;
> with Ada.Streams.Stream_IO;
> with Archiver;
>
> procedure Main is
>
>  A : Archiver.Archiver_t;
>  S : constant Ada.Streams.Stream_IO.Stream_Access := Archiver.Stream
> (Archiver.Open_Archive (A, "file.zip"));
>  X : Integer;
>
> begin
>  X := Integer'Input (S);
>
>  Ada.Text_IO.Put_Line (Integer'Image (X));
> end Main;
>
>
> -- 
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140
>
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140


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

* [Bug ada/42140] GNAT appears to misbehave with limited tagged types and possibly finalization
  2009-11-22  5:22 [Bug ada/42140] New: GNAT appears to misbehave with limited tagged types and possibly finalization gcc at coreland dot ath dot cx
                   ` (2 preceding siblings ...)
  2009-11-22 17:02 ` john at johnnowak dot com
@ 2009-11-22 17:11 ` gcc at coreland dot ath dot cx
  2009-11-22 18:37 ` gcc at coreland dot ath dot cx
  4 siblings, 0 replies; 6+ messages in thread
From: gcc at coreland dot ath dot cx @ 2009-11-22 17:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from gcc at coreland dot ath dot cx  2009-11-22 17:10 -------
Quiet you.

My code might be a lot better if I didn't create dangling references
in the second example.

I think the short example is basically just broken code and entirely
my fault. The code linked to in the git repository isn't, however.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140


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

* [Bug ada/42140] GNAT appears to misbehave with limited tagged types and possibly finalization
  2009-11-22  5:22 [Bug ada/42140] New: GNAT appears to misbehave with limited tagged types and possibly finalization gcc at coreland dot ath dot cx
                   ` (3 preceding siblings ...)
  2009-11-22 17:11 ` gcc at coreland dot ath dot cx
@ 2009-11-22 18:37 ` gcc at coreland dot ath dot cx
  4 siblings, 0 replies; 6+ messages in thread
From: gcc at coreland dot ath dot cx @ 2009-11-22 18:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from gcc at coreland dot ath dot cx  2009-11-22 18:37 -------
Closing this bug as the discussion has become confused between
two separate issues, one of them apparently invalid.


-- 

gcc at coreland dot ath dot cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42140


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

end of thread, other threads:[~2009-11-22 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-22  5:22 [Bug ada/42140] New: GNAT appears to misbehave with limited tagged types and possibly finalization gcc at coreland dot ath dot cx
2009-11-22  5:27 ` [Bug ada/42140] " gcc at coreland dot ath dot cx
2009-11-22 16:41 ` gcc at coreland dot ath dot cx
2009-11-22 17:02 ` john at johnnowak dot com
2009-11-22 17:11 ` gcc at coreland dot ath dot cx
2009-11-22 18:37 ` gcc at coreland dot ath dot cx

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).