From 126740ee0b6facfc578078874afbaaf3b3bffaf7 Mon Sep 17 00:00:00 2001 From: ebotcazou Date: Fri, 21 May 2010 10:02:07 +0000 Subject: [PATCH] PR middle-end/44101 * gimplify.c (gimplify_init_constructor): Build a VIEW_CONVERT_EXPR around the uniquized constructor if its type requires a conversion. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159655 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/gimplify.c | 7 +++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/other/const3.C | 23 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/const3.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f666191353a9..ac091e5eab9f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-05-21 Eric Botcazou + + PR middle-end/44101 + * gimplify.c (gimplify_init_constructor): Build a VIEW_CONVERT_EXPR + around the uniquized constructor if its type requires a conversion. + 2010-05-21 Jakub Jelinek PR debug/44205 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 8f19cedb053a..f5bd994ffbbe 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3813,8 +3813,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, if (notify_temp_creation) return GS_ERROR; - walk_tree (&ctor, force_labels_r, NULL, NULL); - TREE_OPERAND (*expr_p, 1) = tree_output_constant_def (ctor); + walk_tree (&ctor, force_labels_r, NULL, NULL); + ctor = tree_output_constant_def (ctor); + if (!useless_type_conversion_p (type, TREE_TYPE (ctor))) + ctor = build1 (VIEW_CONVERT_EXPR, type, ctor); + TREE_OPERAND (*expr_p, 1) = ctor; /* This is no longer an assignment of a CONSTRUCTOR, but we still may have processing to do on the LHS. So diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 77bc1350cc97..a0740aac91a6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-05-21 Eric Botcazou + + * g++.dg/other/const3.C: New test. + 2010-05-20 Daniel Franke PR fortran/38407 diff --git a/gcc/testsuite/g++.dg/other/const3.C b/gcc/testsuite/g++.dg/other/const3.C new file mode 100644 index 000000000000..d47133b455a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/const3.C @@ -0,0 +1,23 @@ +// PR middle-end/44101 +// { dg-do compile } + +extern bool equal (int[], int[], const int[]); +extern bool equal (wchar_t[], wchar_t[], const wchar_t[]); + +void foo(void) +{ + const int A1[] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; + const int N1 = sizeof(A1) / sizeof(int); + int i1[N1]; + + if (equal(i1, i1 + N1, A1)) + return; + + const wchar_t A3[] = {L'\3', L'\3', L'\3', L'\3', L'\3', + L'\3', L'\3', L'\3', L'\3', L'\3'}; + const int N3 = sizeof(A3) / sizeof(wchar_t); + wchar_t i3[N3]; + + if (equal(i3, i3 + N3, A3)) + return; +} -- 2.47.2