public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/105109 - bogus uninit diagnostic with _Complex
Date: Thu, 31 Mar 2022 10:35:35 +0200 (CEST)	[thread overview]
Message-ID: <20220331083536.013CD133D4@imap2.suse-dmz.suse.de> (raw)

When update_address_taken rewrites a _Complex into SSA it changes
stores to real/imaginary parts to loads of the other component and
a COMPLEX_EXPR.  That matches what gimplification does but it misses
suppression of diagnostics for the load of the other component.
The following patch adds that, syncing up gimplification and
update_address_taken behavior.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-03-31  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/105109
	* tree-ssa.cc (execute_update_addresses_taken): Suppress
	diagnostics on the load of the other complex component.

	* gcc.dg/uninit-pr105109.c: New testcase.
---
 gcc/testsuite/gcc.dg/uninit-pr105109.c | 15 +++++++++++++++
 gcc/tree-ssa.cc                        |  1 +
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/uninit-pr105109.c

diff --git a/gcc/testsuite/gcc.dg/uninit-pr105109.c b/gcc/testsuite/gcc.dg/uninit-pr105109.c
new file mode 100644
index 00000000000..001003ca261
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr105109.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized" } */
+
+static void foo(int dim,float _Complex f0[])
+{
+  int d;
+  f0[0] -= 3.14;  /* { dg-bogus "uninitialized" } */
+  for (d = 0; d < dim; ++d) f0[0] += 3.14;
+}
+void bar(int dim, const float _Complex u_t[], float _Complex f0[])
+{
+  float _Complex exp[1] = {0.};
+  foo(dim, exp);
+  f0[0] = u_t[0] - exp[0];
+}
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index 6dcb3142869..a362a0a9ea6 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1905,6 +1905,7 @@ execute_update_addresses_taken (void)
 					? REALPART_EXPR : IMAGPART_EXPR,
 					TREE_TYPE (other),
 					TREE_OPERAND (lhs, 0));
+		    suppress_warning (lrhs);
 		    gimple *load = gimple_build_assign (other, lrhs);
 		    location_t loc = gimple_location (stmt);
 		    gimple_set_location (load, loc);
-- 
2.34.1

                 reply	other threads:[~2022-03-31  8:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220331083536.013CD133D4@imap2.suse-dmz.suse.de \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).