public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Qing Zhao <qinzhao@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7411] Suppress uninitialized warnings for new created uses from __builtin_clear_padding folding [PR104550]
Date: Mon, 28 Feb 2022 15:58:57 +0000 (GMT)	[thread overview]
Message-ID: <20220228155857.63B113858C83@sourceware.org> (raw)

https://gcc.gnu.org/g:3f3246eb16f554c70c5ce87ad2c785f83adb4625

commit r12-7411-g3f3246eb16f554c70c5ce87ad2c785f83adb4625
Author: Qing Zhao <qing.zhao@oracle.com>
Date:   Mon Feb 28 15:58:43 2022 +0000

    Suppress uninitialized warnings for new created uses from __builtin_clear_padding folding [PR104550]
    
    __builtin_clear_padding(&object) will clear all the padding bits of the object.
    actually, it doesn't involve any use of an user variable. Therefore, users do
    not expect any uninitialized warning from it. It's reasonable to suppress
    uninitialized warnings for all new created uses from __builtin_clear_padding
    folding.
    
            PR middle-end/104550
    
    gcc/ChangeLog:
    
            * gimple-fold.cc (clear_padding_flush): Suppress warnings for new
            created uses.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/auto-init-pr104550-1.c: New test.
            * gcc.dg/auto-init-pr104550-2.c: New test.
            * gcc.dg/auto-init-pr104550-3.c: New test.

Diff:
---
 gcc/gimple-fold.cc                          | 12 +++++++++++-
 gcc/testsuite/gcc.dg/auto-init-pr104550-1.c | 10 ++++++++++
 gcc/testsuite/gcc.dg/auto-init-pr104550-2.c | 11 +++++++++++
 gcc/testsuite/gcc.dg/auto-init-pr104550-3.c | 11 +++++++++++
 4 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 16f02c2d098..c9179abb27e 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -4379,7 +4379,17 @@ clear_padding_flush (clear_padding_struct *buf, bool full)
 	      else
 		{
 		  src = make_ssa_name (type);
-		  g = gimple_build_assign (src, unshare_expr (dst));
+		  tree tmp_dst = unshare_expr (dst);
+		  /* The folding introduces a read from the tmp_dst, we should
+		     prevent uninitialized warning analysis from issuing warning
+		     for such fake read.  In order to suppress warning only for
+		     this expr, we should set the location of tmp_dst to
+		     UNKNOWN_LOCATION first, then suppress_warning will call
+		     set_no_warning_bit to set the no_warning flag only for
+		     tmp_dst.  */
+		  SET_EXPR_LOCATION (tmp_dst, UNKNOWN_LOCATION);
+		  suppress_warning (tmp_dst, OPT_Wuninitialized);
+		  g = gimple_build_assign (src, tmp_dst);
 		  gimple_set_location (g, buf->loc);
 		  gsi_insert_before (buf->gsi, g, GSI_SAME_STMT);
 		  tree mask = native_interpret_expr (type,
diff --git a/gcc/testsuite/gcc.dg/auto-init-pr104550-1.c b/gcc/testsuite/gcc.dg/auto-init-pr104550-1.c
new file mode 100644
index 00000000000..a08110c3a17
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/auto-init-pr104550-1.c
@@ -0,0 +1,10 @@
+/* PR 104550*/
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized -ftrivial-auto-var-init=pattern" } */
+struct vx_audio_level {
+ int has_monitor_level : 1;
+};
+
+void vx_set_monitor_level() {
+ struct vx_audio_level info; /* { dg-bogus "info" "is used uninitialized" } */
+}
diff --git a/gcc/testsuite/gcc.dg/auto-init-pr104550-2.c b/gcc/testsuite/gcc.dg/auto-init-pr104550-2.c
new file mode 100644
index 00000000000..2c395b32d32
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/auto-init-pr104550-2.c
@@ -0,0 +1,11 @@
+/* PR 104550 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized -ftrivial-auto-var-init=zero" } */
+struct vx_audio_level {
+ int has_monitor_level : 1;
+};
+
+void vx_set_monitor_level() {
+ struct vx_audio_level info; 
+ __builtin_clear_padding (&info);  /* { dg-bogus "info" "is used uninitialized" } */ 
+}
diff --git a/gcc/testsuite/gcc.dg/auto-init-pr104550-3.c b/gcc/testsuite/gcc.dg/auto-init-pr104550-3.c
new file mode 100644
index 00000000000..9893e37f12d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/auto-init-pr104550-3.c
@@ -0,0 +1,11 @@
+/* PR 104550 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wuninitialized -ftrivial-auto-var-init=pattern" } */
+struct vx_audio_level {
+ int has_monitor_level : 1;
+};
+
+void vx_set_monitor_level() {
+ struct vx_audio_level info;   /* { dg-bogus "info" "is used uninitialized" } */
+ __builtin_clear_padding (&info);  /* { dg-bogus "info" "is used uninitialized" } */ 
+}


                 reply	other threads:[~2022-02-28 15:58 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=20220228155857.63B113858C83@sourceware.org \
    --to=qinzhao@gcc.gnu.org \
    --cc=gcc-cvs@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).