public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re:  Q about Ada and value ranges in types
@ 2005-05-03  1:46 Richard Kenner
  2005-05-03 14:16 ` Diego Novillo
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Kenner @ 2005-05-03  1:46 UTC (permalink / raw)
  To: dnovillo; +Cc: gcc

    I am tracking an ICE in VRP that triggers only in Ada.  Given
    this:

     1	D.1480_32 = nam_30 - 300000361;
     2	if (D.1480_32 <= 1) goto <L112>; else goto <L52>;
     3	<L112>:;
     4	D.1480_94 = ASSERT_EXPR <D.1480_32, D.1480_32 <= 1>;
     5	goto <bb 50> (<L57>);

    for name D.1480_94.  However, the type of D.1480 is:

    (gdb) ptu type
     const types__name_id___XDLU_300000000__399999999

     <integer_type 0xf6f3f360 types__name_id___XDLU_300000000__399999999
        type <integer_type 0xf6f3cec4 types__Tname_idB sizes-gimplified visited
    [ ... ]
         min <integer_cst 0xf6f40060 300000000>
        max <integer_cst 0xf6f40090 399999999>
         RM size <integer_cst 0xf6ee13f0 32>>

    My question is, is Ada emitting an always-false predicate in line
    #2?  Or is it a bug?

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.

    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.

(Note that there's a system problem and email to this address won't be
received until tomorrow afternoon.)

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Q about Ada and value ranges in types
@ 2005-06-28  2:28 Richard Kenner
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Kenner @ 2005-06-28  2:28 UTC (permalink / raw)
  To: ja2morri; +Cc: gcc

    RTH has been suggesting to use build_int_cst (etype, 0) instead.

Indeed.  I was trying to minimize the change, but such cleanups are always
useful.  This was also missing a protection on INTEGER_TYPE_P.  I just got
a good bootstrap of Ada on x86_64 with this and a patch from Diego to fix
the other problem and also remove the kludge that's fixed by this.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Q about Ada and value ranges in types
@ 2005-06-27 20:48 Richard Kenner
  2005-06-27 23:36 ` James A. Morrison
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Kenner @ 2005-06-27 20:48 UTC (permalink / raw)
  To: dnovillo; +Cc: gcc

Sorry it took me so long to get to this.

    > 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.

As it turned out, there was.

    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:

I'd also assumed this was where the bogus tree came from, but I was wrong.
The node in question was not made by the Ada front end but by
build_range_check in clearly incorrect code that does the subtraction in the
wrong type.

This fixes that problem.  Are you in a position to check if it fixes the
original issue?

*** fold-const.c	25 Jun 2005 01:59:57 -0000	1.599
--- fold-const.c	27 Jun 2005 20:44:56 -0000
*************** build_range_check (tree type, tree exp, 
*** 4027,4034 ****
  
    if (value != 0 && ! TREE_OVERFLOW (value))
!     return build_range_check (type,
! 			      fold_build2 (MINUS_EXPR, etype, exp, low),
! 			      1, fold_convert (etype, integer_zero_node),
! 			      value);
  
    return 0;
--- 4027,4045 ----
  
    if (value != 0 && ! TREE_OVERFLOW (value))
!     {
!       /* There is no requirement that LOW be within the range of ETYPE
! 	 if the latter is a subtype.  It must, however, be within the base
! 	 type of ETYPE.  So be sure we do the subtraction in that type.  */
!       if (TREE_TYPE (etype))
! 	{
! 	  etype = TREE_TYPE (etype);
! 	  value = fold_convert (etype, value);
! 	}
! 
!       return build_range_check (type,
! 				fold_build2 (MINUS_EXPR, etype, exp, low),
! 				1, fold_convert (etype, integer_zero_node),
! 				value);
!     }
  
    return 0;

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Q about Ada and value ranges in types
@ 2005-05-03 22:20 Richard Kenner
  2005-05-04  0:40 ` Diego Novillo
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Kenner @ 2005-05-03 22:20 UTC (permalink / raw)
  To: dnovillo; +Cc: gcc

     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).

As of right now, I don't think this is a VRP problem, but something wrong
with the tree Ada produces.

     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:

I'm out of town until tomorrow and will do this then.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Q about Ada and value ranges in types
@ 2005-05-02 15:26 Diego Novillo
  0 siblings, 0 replies; 8+ messages in thread
From: Diego Novillo @ 2005-05-02 15:26 UTC (permalink / raw)
  To: gcc

I am tracking an ICE in VRP that triggers only in Ada.  Given
this:

     1	D.1480_32 = nam_30 - 300000361;
     2	if (D.1480_32 <= 1) goto <L112>; else goto <L52>;
     3	<L112>:;
     4	D.1480_94 = ASSERT_EXPR <D.1480_32, D.1480_32 <= 1>;
     5	goto <bb 50> (<L57>);


When visiting statemen #4, VRP tries to create the range [-INF, 1] 
for name D.1480_94.  However, the type of D.1480 is:

(gdb) ptu type
const types__name_id___XDLU_300000000__399999999

 <integer_type 0xf6f3f360 types__name_id___XDLU_300000000__399999999
    type <integer_type 0xf6f3cec4 types__Tname_idB sizes-gimplified visited SI
[ ... ]
    min <integer_cst 0xf6f40060 300000000>
    max <integer_cst 0xf6f40090 399999999>
     RM size <integer_cst 0xf6ee13f0 32>>


So, for this type -INF is 300000000, and thus the range that we
try to create is [300000000, 1] which is invalid.

My question is, is Ada emitting an always-false predicate in line
#2?  Or is it a bug?  What would happen if nam_30 (also of the
same type) was 300000000?

If the Ada language allows that kind of runtime check, then my
fix to VRP will be different.  On examining 'D.1480_32 = name_30
- 300000361' we could create the range [300000000, 399999999] for
D.1480_32 and fold statement #2 directly.


Thanks.  Diego.

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

end of thread, other threads:[~2005-06-28  2:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-03  1:46 Q about Ada and value ranges in types Richard Kenner
2005-05-03 14:16 ` Diego Novillo
  -- strict thread matches above, loose matches on Subject: below --
2005-06-28  2:28 Richard Kenner
2005-06-27 20:48 Richard Kenner
2005-06-27 23:36 ` James A. Morrison
2005-05-03 22:20 Richard Kenner
2005-05-04  0:40 ` Diego Novillo
2005-05-02 15:26 Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).