comp.lang.ada
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: What is the warning about builtin-function on gcc-4.6.0 ?
Date: Sun, 27 Mar 2011 10:37:44 +0200
Date: 2011-03-27T10:37:44+02:00	[thread overview]
Message-ID: <87vcz5ot5z.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: imm67s$49s$1@munin.nbi.dk

* Randy Brukardt:

> "Florian Weimer" <fw@deneb.enyo.de> wrote in message 
> news:8762r5hl2u.fsf@mid.deneb.enyo.de...
> ...
>>> If the compiler doesn't raise an exception on division by zero (it's
>>> allowed not to, and GNAT doesn't) it will (in this case) set the result
>>> to +Inf, and 'Valid will return False.
>>
>> My understanding is that an implementation must either raise
>> Constraint_Error, or the evaluation of an expression must result in a
>> valid value.
>
> Your understanding is wrong.
>
> The only real requirement on Ada math is that the resulting values are not 
> used in a way that causes erroneous execution (and there is even an explicit 
> hole allowing that for Unchecked_Conversion). Otherwise, using/producing an 
> "invalid value" is allowed in almost all contexts -- but it is a bounded 
> error so a compiler can raise an exception if it wants.

I'm bothered by this reasoning because it means that Ada compilers
don't have to implement any overflow checks on integer arithmetic.
This is at odds with the existing Ada literature, and existing ACATS
tests (C45632A, for example).

A concrete example: Suppose that A, B are of type Integer, and
Integer'Base has the same range as Integer, and A + B gives a
mathematical result outside this range.  The implementation chooses to
produce an "invalid value" for the result.  During actual execution on
real hardware, it is represented as the lower Integer'Size bits of the
result.  This representation will not cause erroneous execution on its
own, so it passes the test in 13.9.1.

> Also note that "abnormal" is something different from "invalid" (only scalar 
> objects can be invalid).

It's also not clear whether "abnormal" and "not normal" and "invalid"
and "not valid" are equivalent.  (You cannot detect values which are
conceptually invalid by inspecting the 'Valid attribute at run time
because it produces false negatives, but this is a different matter.)

> Data validity is a very complex subject; you can read 13.9.1 10
> times and get different impressions each time.

I don't think 13.9.1 comes into play at all.  It says what happens
with invalid representations, but doesn't say how they are produced.
(The standard doesn't say much at all about the behavior of Ada
programs if you can invoke 13.9.1 whenever it's convenient.)



  reply	other threads:[~2011-03-27  8:37 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-26  6:32 What is the warning about builtin-function on gcc-4.6.0 ? ytomino
2011-03-26  8:45 ` Florian Weimer
2011-03-26  9:13   ` ytomino
2011-03-26  9:43     ` Florian Weimer
2011-03-26 10:07       ` ytomino
2011-03-26 10:24         ` Florian Weimer
2011-03-26 15:14           ` Dmitry A. Kazakov
2011-03-26 21:36             ` ytomino
2011-03-27  9:50               ` Dmitry A. Kazakov
2011-03-26 14:50         ` Simon Wright
2011-03-26 15:50           ` Florian Weimer
2011-03-26 16:32             ` Simon Wright
2011-03-26 17:02               ` Florian Weimer
2011-03-26 17:48                 ` Simon Wright
2011-03-26 18:48                   ` Florian Weimer
2011-03-27  2:08                 ` Randy Brukardt
2011-03-27  8:37                   ` Florian Weimer [this message]
2011-03-27 16:41                     ` Robert A Duff
2011-03-27 17:21                       ` Florian Weimer
2011-03-27 17:56                         ` Robert A Duff
2011-03-27 16:51                     ` Robert A Duff
2011-03-27 17:05                       ` Florian Weimer
2011-03-27 17:14                         ` Robert A Duff
2011-03-29  2:20                           ` Randy Brukardt
2011-03-29 18:35                             ` Robert A Duff
2011-03-29 23:35                               ` Randy Brukardt
2011-03-30  1:02                               ` Adam Beneschan
2011-03-30 12:57                                 ` Robert A Duff
2011-03-30 14:41                                   ` Adam Beneschan
2011-03-30 18:39                                     ` Robert A Duff
2011-03-30 19:28                                   ` Randy Brukardt
2011-03-26 21:58       ` ytomino
2011-03-26 22:00         ` Florian Weimer
2011-03-26 22:22 ` anon
2011-03-26 22:36   ` ytomino
2011-03-27 12:00     ` anon
2011-03-27 18:50       ` ytomino
2011-03-27 23:35         ` anon
2011-03-27 23:42         ` anon
replies disabled

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