aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/gimplify.cc2
-rw-r--r--gcc/testsuite/c-c++-common/init-7.c39
2 files changed, 41 insertions, 0 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index fd18d8b..827941b 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -5420,6 +5420,8 @@ gimplify_init_ctor_eval (tree object, vec<constructor_elt, va_gc> *elts,
cref = build2 (MEM_REF, rtype, addr,
build_int_cst (ptr_type_node, 0));
rctor = tree_output_constant_def (rctor);
+ if (!useless_type_conversion_p (rtype, TREE_TYPE (rctor)))
+ rctor = build1 (VIEW_CONVERT_EXPR, rtype, rctor);
if (gimplify_expr (&cref, pre_p, NULL, is_gimple_lvalue,
fb_lvalue) != GS_ERROR)
gimplify_seq_add_stmt (pre_p,
diff --git a/gcc/testsuite/c-c++-common/init-7.c b/gcc/testsuite/c-c++-common/init-7.c
new file mode 100644
index 0000000..8df387c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/init-7.c
@@ -0,0 +1,39 @@
+/* PR middle-end/117384 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void baz (signed char *, unsigned char *);
+
+void
+foo (void)
+{
+ signed char b[] = {
+ 44, 28, 12, 96, 80, 64, 48, 32, 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 24, 39, 54, 69, 84, 99, 114, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36
+ };
+ baz (b, 0);
+}
+
+void
+bar (void)
+{
+ unsigned char b[] = {
+ 44, 28, 12, 96, 80, 64, 48, 32, 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 24, 39, 54, 69, 84, 99, 114, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36,
+ 53, 36, 19, 102, 85, 68, 51, 34, 17, 34, 51, 68, 85, 102, 19, 36
+ };
+ baz (0, b);
+}