[PATCH] Fix PR/24599, setting overflow flags on shared constants
Paolo Bonzini
paolo.bonzini@lu.unisi.ch
Sat Nov 5 12:11:00 GMT 2005
The current c-typeck.c code for build_c_cast is
if (CONSTANT_CLASS_P (ovalue))
{
TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW
(ovalue);
}
else
TREE_OVERFLOW (value) = 0;
Given Andrew and Zdenek's analysis in the PR, a quick fix for this bug
could just to add a `value = copy_node (value)' in the `then' branch.
The patch is only slightly more complex than that.
if (CONSTANT_CLASS_P (ovalue)
&& (TREE_OVERFLOW (ovalue)
|| TREE_CONSTANT_OVERFLOW (ovalue)))
{
/* Avoid clobbering a shared constant. */
value = copy_node (value);
TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
}
else if (TREE_OVERFLOW (value) || TREE_CONSTANT_OVERFLOW (value))
/* Reset VALUE's overflow flags, ensuring constant sharing. */
value = build_int_cst_wide (TREE_TYPE (value),
TREE_INT_CST_LOW (value),
TREE_INT_CST_HIGH (value));
1) The `else' branch uses build_int_cst_wide to ensure that the constant
is shared.
2) The copying is only done if the overflow flags have to be set. If
CONSTANT_CLASS_P is set but the ovalue had both overflow flags reset,
the two branches are functionally equivalent but the `else' is more
memory efficient: so, this is what the patch does.
Bootstrapped/tested powerpc-apple-darwin8.2.0, also checked that the
original reporter's testcase is fixed. Ok for mainline? Ok for 4.0
after successful testing there?
Paolo
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr24599.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20051105/c187b437/attachment.ksh>
More information about the Gcc-patches
mailing list