This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix 22439
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 8 Aug 2005 14:46:59 -0700
- Subject: fix 22439
The observable problem is that size_binop gets fed something that
isn't a TYPE_IS_SIZETYPE, and aborts. Given that the value fed
into size_binop came straight from TYPE_SIZE_UNIT, I don't think
that section of code is wrong. I think we have a right to assume
that TYPE_SIZE_UNIT has type sizetype and TYPE_SIZE has type
bitsizetype.
The type mismatch was introduced during gimplify_type_sizes. We
had a NOP_EXPR<sizetype, SAVE_EXPR<n>>, where N is size_t. For
C, the only difference between size_t and sizetype is the actual
TYPE_IS_SIZETYPE bit, and so we discard the cast considering the
two types compatible. Which leads to TYPE_SIZE_UNIT being set to N.
Given that gimple code itself does not care about the difference
between sizetype and size_t, it didn't seem prudent to enforce this
distinction in tree_ssa_useless_type_conversion or the like.
Instead, we can notice the change in the one place that it matters
and enforce type correctness by hand.
Tested on i686 and x86_64 linux.
r~
* gimplify.c (gimplify_one_sizepos): Preserve the original type.
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.143
diff -u -p -d -r2.143 gimplify.c
--- gimplify.c 28 Jul 2005 16:29:51 -0000 2.143
+++ gimplify.c 8 Aug 2005 21:36:40 -0000
@@ -4610,18 +4610,44 @@ gimplify_type_sizes (tree type, tree *li
void
gimplify_one_sizepos (tree *expr_p, tree *stmt_p)
{
+ tree type, expr = *expr_p;
+
/* We don't do anything if the value isn't there, is constant, or contains
A PLACEHOLDER_EXPR. We also don't want to do anything if it's already
a VAR_DECL. If it's a VAR_DECL from another function, the gimplifier
will want to replace it with a new variable, but that will cause problems
if this type is from outside the function. It's OK to have that here. */
- if (*expr_p == NULL_TREE || TREE_CONSTANT (*expr_p)
- || TREE_CODE (*expr_p) == VAR_DECL
- || CONTAINS_PLACEHOLDER_P (*expr_p))
+ if (expr == NULL_TREE || TREE_CONSTANT (expr)
+ || TREE_CODE (expr) == VAR_DECL
+ || CONTAINS_PLACEHOLDER_P (expr))
return;
- *expr_p = unshare_expr (*expr_p);
+ type = TREE_TYPE (expr);
+ *expr_p = unshare_expr (expr);
+
gimplify_expr (expr_p, stmt_p, NULL, is_gimple_val, fb_rvalue);
+ expr = *expr_p;
+
+ /* Verify that we've an exact type match with the original expression.
+ In particular, we do not wish to drop a "sizetype" in favour of a
+ type of similar dimensions. We don't want to pollute the generic
+ type-stripping code with this knowledge because it doesn't matter
+ for the bulk of GENERIC/GIMPLE. It only matters that TYPE_SIZE_UNIT
+ and friends retain their "sizetype-ness". */
+ if (TREE_TYPE (expr) != type && TYPE_IS_SIZETYPE (type))
+ {
+ tree tmp;
+
+ *expr_p = create_tmp_var (type, NULL);
+ tmp = build1 (NOP_EXPR, type, expr);
+ tmp = build2 (MODIFY_EXPR, type, *expr_p, expr);
+ if (EXPR_HAS_LOCATION (expr))
+ SET_EXPR_LOCUS (tmp, EXPR_LOCUS (expr));
+ else
+ SET_EXPR_LOCATION (tmp, input_location);
+
+ gimplify_and_add (tmp, stmt_p);
+ }
}
#ifdef ENABLE_CHECKING