This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] to gimplify_cond_expr for PR c++/86485 - -Wmaybe-unused with empty class ?:


Well, this sent me down rather a rabbit hole of empty class handling.

The main problem in this testcase is that the front end expects an rvalue
COND_EXPR to initialize a single temporary from one of the arms.  But
because gimplify_cond_expr used MODIFY_EXPR, instead the arms would each
create their own temporary and then copy that into the common temporary.

So, let's use INIT_EXPR instead.  Other issues I came across will wait for
stage 1.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* gimplify.c (gimplify_cond_expr): Use INIT_EXPR.
---
 gcc/gimplify.c                     |  4 ++--
 gcc/testsuite/g++.dg/init/empty2.C | 12 ++++++++++++
 gcc/ChangeLog                      |  5 +++++
 3 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/init/empty2.C

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 983635ba21f..fa85b1c86de 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -4024,11 +4024,11 @@ gimplify_cond_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback)
       /* Build the new then clause, `tmp = then_;'.  But don't build the
 	 assignment if the value is void; in C++ it can be if it's a throw.  */
       if (!VOID_TYPE_P (TREE_TYPE (then_)))
-	TREE_OPERAND (expr, 1) = build2 (MODIFY_EXPR, type, tmp, then_);
+	TREE_OPERAND (expr, 1) = build2 (INIT_EXPR, type, tmp, then_);
 
       /* Similarly, build the new else clause, `tmp = else_;'.  */
       if (!VOID_TYPE_P (TREE_TYPE (else_)))
-	TREE_OPERAND (expr, 2) = build2 (MODIFY_EXPR, type, tmp, else_);
+	TREE_OPERAND (expr, 2) = build2 (INIT_EXPR, type, tmp, else_);
 
       TREE_TYPE (expr) = void_type_node;
       recalculate_side_effects (expr);
diff --git a/gcc/testsuite/g++.dg/init/empty2.C b/gcc/testsuite/g++.dg/init/empty2.C
new file mode 100644
index 00000000000..f0d8e3fec01
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/empty2.C
@@ -0,0 +1,12 @@
+// PR c++/86485
+// { dg-additional-options -Wmaybe-uninitialized }
+
+struct E {};
+struct S { S () {} E e; };
+void foo (S);
+
+void
+bar (bool b)
+{
+  foo (b ? S () : S ());
+}
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 405bc38fb75..df50f599d1a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2019-03-02  Jason Merrill  <jason@redhat.com>
+
+	PR c++/86485 - -Wmaybe-unused with empty class ?:
+	* gimplify.c (gimplify_cond_expr): Use INIT_EXPR.
+
 2019-03-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/89587

base-commit: cd5a9ed1f359703439b230d251e0a2bbfd49d100
-- 
2.20.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]