comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Memory overwrite?
Date: Wed, 25 Jan 1995 16:31:55 GMT
Date: 1995-01-25T16:31:55+00:00	[thread overview]
Message-ID: <D2yz98.KC8@world.std.com> (raw)
In-Reply-To: 3g2stg$i0u@miranda.gmrc.gecm.com

In article <3g2stg$i0u@miranda.gmrc.gecm.com>,
R.A.L Williams <bill@valiant> wrote:
>In article <1995Jan18.182039.7324@wdl.loral.com> Mark Biggar wrote:
>: 	if i in index then
>: 		a(i) := 0;
>: 	else
>: 		raise constraint_error;
>: 	end if;
>
>: because an aggressive optimizer will notice that the if test is always true
>: (in the absence of uninitialized variables, but uninitialized variables
>: are erroneous, which allow any behaviour, so it can ignore the problem)
>: and eliminate the test and the else branch completely.

I just want to emphasize that this is no longer true in Ada 95.  In Ada
95, the above will raise an exception if i is not in index, even if its
because i is not initialized.

>: Ada95 add the 'valid attribute to handle this problem.

Not really.  'Valid is mainly for checking data that comes from
Unchecked_Conversion, input, or from another language.  These are
isolated cases, and the programmer can use 'Valid as appropriate.

But variables occur all over the place.  It would not be feasible to put
'Valid checks all over the place, just to make sure you didn't forget to
initialize a variable.

Note the difference in these two cases: using an uninitialized variable
is a bug, and there are numerous places where it *might* happen in any
given program.  Input data, on the other hand, is not under control of
the programmer.  Bad input data is not a program bug.  And the number of
places in a program that do input is relatively small.

Again, using an uninitialized variable is *not* erroneous is Ada 95, so
if an optimizer wants to eliminate a check, it has to prove that the
check will not fail, even in the presence of uninitialized variables.

There's also a feature in the Safety and Security annex that tells the
compiler to initialize things to an out-of-range value (if it fits in
the bits of the object), to increase the likelihood that using an
uninitialized variable will cause the program to trip over a constraint
check.

- Bob



  reply	other threads:[~1995-01-25 16:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-01-24 12:47 Memory overwrite? R.A.L Williams
1995-01-25 16:31 ` Robert A Duff [this message]
1995-01-25 19:01 ` Tucker Taft
1995-01-25 21:24 ` Robert Dewar
1995-01-30 17:06 ` Theodore E. Dennison
1995-02-01 12:25   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1995-01-26 13:05 R.A.L Williams
1995-01-27 14:01 ` Robert A Duff
1995-01-28 22:49   ` Robert Dewar
1995-01-30 14:16     ` Robert A Duff
1995-02-01 23:00       ` Matt Kennel
1995-01-28  5:54 ` Robert Dewar
1995-01-13  8:35 Rick Wouters
     [not found] ` <3fe5cp$fnq@theopolis.orl.mmc.com>
1995-01-18 18:20   ` Mark A Biggar
1995-01-20  5:19     ` 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