This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New Jacks Regressions: Constant Folding of Casts


On Tue, 20 Jul 2004 07:16:52 -0600 (MDT), Roger Sayle
<roger@eyesopen.com> wrote:
> 
> That's a relief :).  It might be related to Steve Bosschers improvements
> to switch statement handling.  The middle-end now does far less processing
> of switch/case statements, and expects the front-end to issue diagnostics,
> remove duplicate case nodes, etc...  Perhaps the java front-end has been
> relying on the middle-end to call "fold" on case nodes for it.  Could you
> check that "((int)Float.Nan == 0 ? 1 : 0" is being folded as its being
> constructed.  Does "case (int)Float.Nan:" work?

No, "case (int )Float.NaN:" also doesn't work.

The Java front end does call fold() on case nodes.
Here's the relevant code from java/parse.y:
-------------------------- 8< --------------------------
  11533       /* First, the case expression must be constant. Values of final
  11534          fields are accepted. */
  11535       cn = fold (cn);
  11536       if ((TREE_CODE (cn) == COMPOUND_EXPR || TREE_CODE (cn)
== COMPONENT_REF)
  11537           && JDECL_P (TREE_OPERAND (cn, 1))
  11538           && FIELD_FINAL (TREE_OPERAND (cn, 1))
  11539           && DECL_INITIAL (TREE_OPERAND (cn, 1)))
  11540         {
  11541           cn = fold_constant_for_init (DECL_INITIAL
(TREE_OPERAND (cn, 1)),
  11542                                        TREE_OPERAND (cn, 1));
  11543         }
  11544       /* Accept final locals too. */
  11545       else if (TREE_CODE (cn) == VAR_DECL && DECL_FINAL (cn)
  11546                && DECL_INITIAL (cn))
  11547         cn = fold_constant_for_init (DECL_INITIAL (cn), cn);
  11548
  11549       if (!TREE_CONSTANT (cn) && !flag_emit_xref)
  11550         {
  11551           EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
  11552           parse_error_context (node, "Constant expression required");
  11553           return error_mark_node;
  11554         }
-------------------------- 8< --------------------------

Has this become invalid now?

And just for your benefit, the value of "cn" before
the first call to fold( ) (for the "case (int )Float.NaN:"
case) is:
-------------------------- 8< --------------------------
Breakpoint 1, java_complete_lhs (node=0x4001cd00) at parse.y:11535
11535         cn = fold (cn);
(gdb) p debug_tree(cn)
 <cond_expr 0x40220730
    type <integer_type 0x40020414 int SI
        size <integer_cst 0x4001e2d0 constant invariant 32>
        unit size <integer_cst 0x4001e330 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst
0x4001e300 -2147483648> max <integer_cst 0x4001e318 2147483647>
        pointer_to_this <pointer_type 0x40165488> chain <type_decl
0x40020488 int>>
    tree_6
    arg 0 <unlt_expr 0x4001f45c
        type <boolean_type 0x40026000 boolean unsigned QI
            size <integer_cst 0x4001e930 constant invariant 8>
            unit size <integer_cst 0x4001e8e8 constant invariant 1>
            align 8 symtab 0 alias set -1 precision 1 min <integer_cst
0x4001ea38 0> max <integer_cst 0x4001ea50 1>
            chain <type_decl 0x40026074 boolean>>
        constant invariant
        arg 0 <real_cst 0x40169ae0 type <real_type 0x40026488 float>
            constant invariant Nan>
        arg 1 <real_cst 0x4021f348 type <real_type 0x40026488 float>
            constant invariant 2.147483648e+9>>
    arg 1 <cond_expr 0x402206e0 type <integer_type 0x40020414 int>

        arg 0 <le_expr 0x4001f414 type <boolean_type 0x40026000 boolean>
            constant invariant arg 0 <real_cst 0x40169ae0 Nan>
            arg 1 <real_cst 0x4021f318 type <real_type 0x40026488 float>
                constant invariant -2.147483648e+9>>
        arg 1 <integer_cst 0x4001e300 constant invariant -2147483648>
        arg 2 <cond_expr 0x402206b8 type <integer_type 0x40020414 int>

            arg 0 <ne_expr 0x4001f3f0 type <boolean_type 0x40026000 boolean>
                constant invariant arg 0 <real_cst 0x40169ae0 Nan> arg
1 <real_cst 0x40169ae0 Nan>>
            arg 1 <integer_cst 0x4001e840 constant invariant 0>
            arg 2 <fix_trunc_expr 0x4021d400 type <integer_type 0x40020414 int>
                constant invariant arg 0 <real_cst 0x40169ae0 Nan>>>>
    arg 2 <integer_cst 0x4001e318 type <integer_type 0x40020414 int>
constant invariant 2147483647>>
-------------------------- 8< --------------------------

Thanks,
Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT gmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]