This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: PATCH to initializer_constant_valid_p for c++/38880
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>, Ian Lance Taylor <iant at google dot com>
- Date: Wed, 18 Feb 2009 20:29:51 -0500
- Subject: RFA: PATCH to initializer_constant_valid_p for c++/38880
Fixing this bug in either fold or the front end had the same problem of
making the pseudo-offsetof expression look like a valid C++
constant-expression, when it should not be. We just want it to be
accepted by initializer_constant_valid_p. As it turns out, we just need
to make the existing code accept PLUS_EXPR as well as POINTER_PLUS_EXPR,
now that we no longer fold the former into the latter in this case.
Ian, was there any particular reason for limiting narrowing support to
POINTER_PLUS_EXPR and MINUS_EXPR, but not PLUS_EXPR? The testcase was
failing because we fold the MINUS_EXPR to a PLUS_EXPR with the second
operand negated.
Tested x86_64-pc-linux-gnu.
OK for trunk?
2009-02-18 Jason Merrill <jason@redhat.com>
PR c++/38880
* varasm.c (initializer_constant_valid_p) [PLUS_EXPR]: Check
narrowing_initializer_constant_valid_p.
Index: varasm.c
===================================================================
*** varasm.c (revision 144271)
--- varasm.c (working copy)
*************** initializer_constant_valid_p (tree value
*** 4316,4327 ****
}
/* 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:
--- 4316,4325 ----
}
/* 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 144271)
--- 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" } }