This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFA: PATCH to initializer_constant_valid_p for c++/38880
Ian Lance Taylor wrote:
Use a cast. The initializer_constant_valid_p code will look through
casts.
Good point, with a cast I was able to make it do odd things. Fixed
thus, and regression tested x86_64-pc-linux-gnu. OK for trunk?
2009-02-23 Jason Merrill <jason@redhat.com>
PR c++/38880
* varasm.c (initializer_constant_valid_p) [PLUS_EXPR]: Check
narrowing_initializer_constant_valid_p.
(narrowing_initializer_constant_valid_p): Don't return
null_pointer_node for adding a pointer to itself.
Index: varasm.c
===================================================================
*** varasm.c (revision 144391)
--- varasm.c (working copy)
*************** constructor_static_from_elts_p (const_tr
*** 4070,4077 ****
&& !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
}
! /* A subroutine of initializer_constant_valid_p. VALUE is either a
! MINUS_EXPR or a POINTER_PLUS_EXPR. This looks for cases of VALUE
which are valid when ENDTYPE is an integer of any size; in
particular, this does not accept a pointer minus a constant. This
returns null_pointer_node if the VALUE is an absolute constant
--- 4070,4077 ----
&& !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
}
! /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
! PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
which are valid when ENDTYPE is an integer of any size; in
particular, this does not accept a pointer minus a constant. This
returns null_pointer_node if the VALUE is an absolute constant
*************** narrowing_initializer_constant_valid_p (
*** 4124,4130 ****
/* Both initializers must be known. */
if (op0 && op1)
{
! if (op0 == op1)
return null_pointer_node;
/* Support differences between labels. */
--- 4124,4132 ----
/* Both initializers must be known. */
if (op0 && op1)
{
! if (op0 == op1
! && (op0 == null_pointer_node
! || TREE_CODE (value) == MINUS_EXPR))
return null_pointer_node;
/* Support differences between labels. */
*************** initializer_constant_valid_p (tree value
*** 4315,4326 ****
}
/* Support narrowing pointer differences. */
! if (TREE_CODE (value) == POINTER_PLUS_EXPR)
! {
! ret = narrowing_initializer_constant_valid_p (value, endtype);
! if (ret != NULL_TREE)
! return ret;
! }
break;
case MINUS_EXPR:
--- 4317,4326 ----
}
/* Support narrowing pointer differences. */
! ret = narrowing_initializer_constant_valid_p (value, endtype);
! if (ret != NULL_TREE)
! return ret;
!
break;
case MINUS_EXPR:
Index: testsuite/g++.dg/init/const7.C
===================================================================
*** testsuite/g++.dg/init/const7.C (revision 144391)
--- testsuite/g++.dg/init/const7.C (working copy)
*************** short offsets[1] = {
*** 9,13 ****
// This ensures that we get a dump whether or not the bug is present.
void fn() { }
! // { dg-final { scan-tree-dump-not "initialization" "gimple" { xfail *-*-* } } }
// { dg-final { cleanup-tree-dump "gimple" } }
--- 9,13 ----
// This ensures that we get a dump whether or not the bug is present.
void fn() { }
! // { dg-final { scan-tree-dump-not "initialization" "gimple" } }
// { dg-final { cleanup-tree-dump "gimple" } }
Index: testsuite/g++.dg/init/static-init1.C
===================================================================
*** testsuite/g++.dg/init/static-init1.C (revision 0)
--- testsuite/g++.dg/init/static-init1.C (revision 0)
***************
*** 0 ****
--- 1,5 ----
+ // Related to the patch for 38880.
+ // Make sure we don't think we can initialize a at compile time.
+
+ char c;
+ short a[] = { (short)((int)&c + (int)&c) };