]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/110743 - expand RMW uninit detection
authorRichard Biener <rguenther@suse.de>
Wed, 24 Jun 2026 07:36:49 +0000 (09:36 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 24 Jun 2026 11:44:53 +0000 (13:44 +0200)
The following expands the RMW bit clear/set pattern detection to
also cover VIEW_CONVERT_EXPR as it appears when generic word_mode
vectorization is involved.

PR tree-optimization/110743
* tree-ssa-uninit.cc (maybe_warn_operand): Also cover
VIEW_CONVERT_EXPR uses for RMW bit clear/set pattern
detection.

* gcc.dg/uninit-pr110743-2.c: New testcase.

gcc/testsuite/gcc.dg/uninit-pr110743-2.c [new file with mode: 0644]
gcc/tree-ssa-uninit.cc

diff --git a/gcc/testsuite/gcc.dg/uninit-pr110743-2.c b/gcc/testsuite/gcc.dg/uninit-pr110743-2.c
new file mode 100644 (file)
index 0000000..8119bb4
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftrivial-auto-var-init=pattern -Wuninitialized" } */
+/* { dg-additional-options "-mgeneral-regs-only" { target { aarch64-*-* x86_64-*-* i?86-*-* } } } */
+
+struct layer_mask {
+    unsigned int x : 17;
+    unsigned int y : 1;
+} __attribute__((__packed__)) __attribute__((__aligned__(sizeof (unsigned int))));
+struct layer_masks {
+  struct layer_mask layers[16];
+};
+
+void bar (struct layer_masks *);
+
+void foo ()
+{
+  struct layer_masks layer_masks; /* { dg-bogus "uninitialized" } */
+  bar (&layer_masks);
+}
index 107ed21e10b878f7828340dc1ee99191ca90534e..1072e1e270bb5cc2f6cdba347dda190bd30d7969 100644 (file)
@@ -768,13 +768,16 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs,
       && single_imm_use (lhs, &luse_p, &use_stmt))
     {
       gassign *use_ass = dyn_cast <gassign *> (use_stmt);
-      for (int i = 0; i < 2; ++i)
+      for (int i = 0; i < 4; ++i)
        if (use_ass
            && (gimple_assign_rhs_code (use_ass) == BIT_AND_EXPR
-               || gimple_assign_rhs_code (use_ass) == BIT_IOR_EXPR)
+               || gimple_assign_rhs_code (use_ass) == BIT_IOR_EXPR
+               || gimple_assign_rhs_code (use_ass) == VIEW_CONVERT_EXPR)
            && single_imm_use (gimple_assign_lhs (use_ass), &luse_p,
                               &use_stmt))
          use_ass = dyn_cast <gassign *> (use_stmt);
+       else
+         break;
       if (use_ass
          && gimple_vdef (use_ass)
          && operand_equal_p (gimple_assign_rhs1 (stmt),