From 80096ea0e8da0110d9d5af05e304963377b1c685 Mon Sep 17 00:00:00 2001 From: dnovillo Date: Fri, 3 Jun 2005 21:07:11 +0000 Subject: [PATCH] * tree-ssa-dom.c (record_edge_info): Use last_basic_block to allocate info array. * tree-vrp.c (extract_range_from_unary_expr): Set resulting range to varying in cast expressions that change TYPE_PRECISION. testsuite/ChangeLog * gcc.dg/tree-ssa/vrp14.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@100554 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++ gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/tree-ssa/vrp14.c | 46 +++++++++++++++++++++++++++++++++++ gcc/tree-ssa-dom.c | 2 +- gcc/tree-vrp.c | 14 ++++++++--- 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp14.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 16841422c6e..be74bb1b786 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2005-06-03 Diego Novillo + + * tree-ssa-dom.c (record_edge_info): Use last_basic_block to + allocate info array. + * tree-vrp.c (extract_range_from_unary_expr): Set resulting + range to varying in cast expressions that change + TYPE_PRECISION. + 2005-06-03 Eric Christopher * config/mips/mips.opt: Add RejectNegative to divide-breaks and diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 523873461f4..3142634db3b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-06-03 Diego Novillo + + * gcc.dg/tree-ssa/vrp14.c: New test. + 2005-06-03 Mark Mitchell PR c++/21336 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp14.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp14.c new file mode 100644 index 00000000000..833a73dcadc --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp14.c @@ -0,0 +1,46 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +struct tree_decl +{ + union tree_decl_u1 { + int f; + long i; + struct tree_decl_u1_a { + unsigned int align : 24; + unsigned int off_align : 8; + } a; + } u1; +}; + +extern void abort (void); + +unsigned int +assemble_variable (struct tree_decl decl) +{ + unsigned int align; + + align = decl.u1.a.align; + + if (align > (1 << ((8 * 4) < 64 ? (8 * 4) - 2 : 62))) + align = (1 << ((8 * 4) < 64 ? (8 * 4) - 2 : 62)); + + /* VRP should not be propagating 0 to the RHS of this assignment. + But it was erroneously applying a cast operation between types of + different precision. align is an unsigned int with range [0, + 0x4000000] but the .align field holds only 24 bits. So the cast + was returning a [0, 0] range. */ + decl.u1.a.align = align; + + return decl.u1.a.align; +} + +main () +{ + struct tree_decl decl; + decl.u1.a.align = 13; + unsigned int x = assemble_variable (decl); + if (x == 0) + abort (); + return 0; +} diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 8e79a46e17f..2bd527a231e 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -2422,7 +2422,7 @@ record_edge_info (basic_block bb) { tree labels = SWITCH_LABELS (stmt); int i, n_labels = TREE_VEC_LENGTH (labels); - tree *info = xcalloc (n_basic_blocks, sizeof (tree)); + tree *info = xcalloc (last_basic_block, sizeof (tree)); edge e; edge_iterator ei; diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 74fb82994ac..373e8d93135 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1295,17 +1295,23 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr) } /* Handle unary expressions on integer ranges. */ - if ((code == NOP_EXPR || code == CONVERT_EXPR) - && (TYPE_SIZE (TREE_TYPE (vr0.min)) != TYPE_SIZE (TREE_TYPE (expr)))) + if (code == NOP_EXPR || code == CONVERT_EXPR) { + tree inner_type = TREE_TYPE (op0); + tree outer_type = TREE_TYPE (expr); + /* When converting types of different sizes, set the result to VARYING. Things like sign extensions and precision loss may change the range. For instance, if x_3 is of type 'long long int' and 'y_5 = (unsigned short) x_3', if x_3 is ~[0, 0], it is impossible to know at compile time whether y_5 will be ~[0, 0]. */ - set_value_range_to_varying (vr); - return; + if (TYPE_SIZE (inner_type) != TYPE_SIZE (outer_type) + || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type)) + { + set_value_range_to_varying (vr); + return; + } } /* Apply the operation to each end of the range and see what we end -- 2.11.4.GIT