comp.lang.ada
 help / color / mirror / Atom feed
* Longstanding GNAT bug, bad code, or both
@ 2004-08-07  2:29 Jeff C,
  2004-08-07  4:05 ` Jeff C,
  2004-08-07 14:07 ` Longstanding GNAT bug, bad code, or both -- Answer..Bad code Jeff C,
  0 siblings, 2 replies; 8+ messages in thread
From: Jeff C, @ 2004-08-07  2:29 UTC (permalink / raw)


The old Intermetrics X11 bindings have been broken since about GNAT 3.13 or
so because
of problems handling events from the X system.. I just verified this is
still broken (solaris 2.8) in gcc 3.4.1

I believe this is due to a GNAT bug related to aliasing and incorrect
assumptions.

The question is this really a GNAT bug or is this code perhaps illegal.

I believe I have a nice simple test case that does not even require the
bindings that shows how
the failure happens.

Basically the problem is that we have a variant record with a default value
for the discriminat at the
point of the type declaration.

A variable of this type is passed to a procedure via a 'access. The
procedure changes the entire
object in what appears to be a legal manner but when the procedure exits and
the main code
tries to access an element of the type that is not available for the default
discriminant value, the code
generates a constraint error due to a discriminant check.

It seemed to me that GNAT is assuming that the variable is not changing when
passed to a procedure
via a 'access. This seemed like a wrong assumption

I also tried it where the procedure that modifies the variable does so via
an out parameter mode.
Again same failure.
Removing the aliased from the variable declaration fixes the problem though
in that case.

This seems pretty clearly to be a broken compiler issue but it has been
broken for so long I find it hard
to believe that this could be the case.




with Text_IO;
procedure Show_Bug is

  type var (A : integer := 0) is
    record
     case A is
      when 0 =>
        Ok : Integer;
      when 1 =>
       Bad : Integer;
      when others =>
         null;
      end case;
    end record;


  procedure see (A : access var) is

  begin
    a.all := (A => 1, Bad => 2);

  end see;

begin
  declare
   I : aliased var;
  begin
    see(I'access);
    Text_IO.Put_Line(Integer'image(I.bad));  --- < Blows up here because
compiler 'thinks' a = 0 but
                                                                    --- 
of course it really is 1 so it should be ok to access bad.
  end;
end Show_Bug;



Jeff Creem





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

end of thread, other threads:[~2004-08-25 11:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-07  2:29 Longstanding GNAT bug, bad code, or both Jeff C,
2004-08-07  4:05 ` Jeff C,
2004-08-07 15:23   ` Stephen Leake
2004-08-07 14:07 ` Longstanding GNAT bug, bad code, or both -- Answer..Bad code Jeff C,
2004-08-07 16:44   ` Stephen Leake
2004-08-08 11:26     ` Simon Wright
2004-08-24 20:57     ` Randy Brukardt
2004-08-25 11:00       ` Jeff C,

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox