Q about Ada and value ranges in types
Diego Novillo
dnovillo@redhat.com
Tue May 3 14:16:00 GMT 2005
On Mon, May 02, 2005 at 09:46:59PM -0400, Richard Kenner wrote:
> You're not showing where this comes from, so it's hard to say. However
> D.1480 is created by the gimplifier, not the Ada front end. There could
> easily be a typing problem in the tree there (e.g., that of the subtraction),
> but I can't tell for sure.
>
Yeah, I didn't show all of it, sorry. My patch to address this
problem includes a more detailed description
(http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00127.html).
Florian Weimer suggested that instead of marking the range as
varying, we could check the super-type to see if it has a wider
range. That is true in this case; the parent type is
types__Tname_idB which has range [-2147483648, 2147483647]. But
I'm not sure if that would be true in general.
> If the Ada language allows that kind of runtime check, then my
> fix to VRP will be different.
>
> I don't see it as a language issue: I'd argue that the tree in statement 2
> is invalid given the typing. That should be true for any language.
>
Dunno. All the operands in the snippet I showed are of the exact
same type (types__name_id___XDLU_300000000__399999999). I'm not
really sure where this type is coming from, but it's relatively
easy to reproduce.
Configure a compiler for target i386-pc-linux-gnu (or any other
i386 variant, not sure if it occurs elsewhere) and compile
ada/sem_intr.adb with:
$ ./xgcc -B./ -c -g -O2 -gnatpg -gnata -I- -I. -Iada -I<src>/gcc/ada <src>/gcc/ada/sem_intr.adb -o ada/sem_intr.o -v -save-temps
Launch gdb and set a bkpt at tree-vrp.c:552 (extract_range_from_assert).
You should get to this ASSERT_EXPR:
ASSERT_EXPR <D.1480_32, D.1480_32 <= 1>
which is in the following context:
-----------------------------------------------------------------------------
;; basic block 44, loop depth 0, count 0
;; prev block 43, next block 84
;; pred: 43 (true,exec)
;; succ: 84 (true,exec) 45 (false,exec)
<L51>:;
D.1478_28 = sinfo__etype (e_5);
nam_30 = sinfo__chars (e_5);
D.1480_32 = nam_30 - 300000361;
if (D.1480_32 <= 1) goto <L112>; else goto <L52>;
;; basic block 84, loop depth 0, count 0
;; prev block 44, next block 45
;; pred: 44 (true,exec)
;; succ: 50 [100.0%] (fallthru)
<L112>:;
D.1480_94 = ASSERT_EXPR <D.1480_32, D.1480_32 <= 1>;
goto <bb 50> (<L57>);
-----------------------------------------------------------------------------
So, after calling sinfo__chars() and subtracting 300000361, the
FE is emitting that range check. AFAICT, the call to
sinfo__chars(e_5) comes from ada/sem_intr.adb:148
Nam : constant Name_Id := Chars (E);
and 'if (D.1480_32 <= 1)' is at line 155:
if Nam = Name_Op_Add
Thanks. Diego.
More information about the Gcc
mailing list