comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Finding out parameters which are not written
Date: 1997/08/12
Date: 1997-08-12T00:00:00+00:00	[thread overview]
Message-ID: <EEtC87.9CC@world.std.com> (raw)
In-Reply-To: 33F07EA1.51D1@aut.alcatel.at


In article <33F07EA1.51D1@aut.alcatel.at>,
Gerhard Radatz  <gerhard.radatz@aut.alcatel.at> wrote:
>Gerhard Radatz wrote:
>> 
>> Does anyone know about a tool which can detect such situations as the
>> following:
>> 
>>         procedure xxx (result: out INTEGER) is
>>         begin
>>              if <<condition>> then
>>                  result := 0;
>>              end if;
>>         end;
>> 
>> Obviously, this proc is erroneous and result will not be written if
>> <<condition>> is FALSE.

>I admit that it is very difficult to find such potential problems at
>compile time. ...

It doesn't seem so hard to me.  The compiler can just check whether
every path through the function assigns to every 'out' parameter of a
scalar type.  If not, warn -- it's almost certainly a bug.  (For
composite types, it's not formally erroneous, and not necessarily a
bug.)  There's no practical reason to worry about the fact that
<<condition>> might be always True (which of course the compiler can't
know, in general).

GNAT does exactly this sort of analysis for function returns -- it makes
sure that every path through the function ends with a return statement,
or the raise of an exception (and it has some mechanism for marking
procedures that always raise an exception).  I don't know if GNAT does
something similar for scalar 'out' parameters, but it could.

Of course, none of this solves the more general problem of uninitialized
objects -- that really requires run-time checks.

- Bob




  reply	other threads:[~1997-08-12  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-08-12  0:00 Finding out parameters which are not written Gerhard Radatz
1997-08-12  0:00 ` Gerhard Radatz
1997-08-12  0:00   ` Robert A Duff [this message]
1997-08-12  0:00     ` Matthew Heaney
1997-08-12  0:00 ` Larry Kilgallen
1997-08-17  0:00   ` Fergus Henderson
     [not found]   ` <5u180q$l69@mulga.cs.mu.OZ.AU>
1997-08-28  0:00     ` Stuart Palin
  -- strict thread matches above, loose matches on Subject: below --
1997-08-27  0:00 Robert Dewar
replies disabled

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