From 0554476dd2c7883716b5ae1d27ae57645921c465 Mon Sep 17 00:00:00 2001 From: rguenth Date: Thu, 9 Dec 2010 17:00:19 +0000 Subject: [PATCH 1/1] 2010-12-09 Richard Guenther PR middle-end/46844 * gimple-fold.c (canonicalize_constructor_val): Canonicalize addresses. * gcc.c-torture/compile/pr46866.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167649 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/gimple-fold.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/compile/pr46866.c | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr46866.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 29c1c32ba83..9dec6e71327 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-12-09 Richard Guenther + + PR middle-end/46844 + * gimple-fold.c (canonicalize_constructor_val): Canonicalize + addresses. + 2010-12-09 Joseph Myers * config/i386/netware.h (TARGET_POSIX_IO): Define. diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index ae4771c903a..ba51ee8d853 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -132,6 +132,10 @@ canonicalize_constructor_val (tree cval) return NULL_TREE; if (base && TREE_CODE (base) == VAR_DECL) add_referenced_var (base); + /* We never have the chance to fixup types in global initializers + during gimplification. Do so here. */ + if (TREE_TYPE (TREE_TYPE (cval)) != TREE_TYPE (TREE_OPERAND (cval, 0))) + cval = build_fold_addr_expr (TREE_OPERAND (cval, 0)); } return cval; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ae01a31ee10..e1317fb5045 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-12-09 Richard Guenther + + PR middle-end/46844 + * gcc.c-torture/compile/pr46866.c: New testcase. + 2010-12-09 John David Anglin PR testsuite/45068 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr46866.c b/gcc/testsuite/gcc.c-torture/compile/pr46866.c new file mode 100644 index 00000000000..4941148571f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr46866.c @@ -0,0 +1,19 @@ +extern void *malloc(__SIZE_TYPE__); +typedef struct T T; +struct T { + void (*destroy)(void *); +}; +void destroy(union { void *this; } __attribute__((transparent_union))); +static const typeof(destroy) *_destroy = (const typeof(destroy)*)destroy; +void destroy(void *this); +static T *create_empty(void) +{ + T *this = malloc(sizeof(*this)); + *this = (typeof(*this)){ _destroy }; + return this; +} +void openssl_crl_load(void) +{ + T *this = create_empty(); + destroy(this); +} -- 2.11.0