https://gcc.gnu.org/g:df1eb95b6e915117dc33cf70dbd46be66c23057f

commit r17-1801-gdf1eb95b6e915117dc33cf70dbd46be66c23057f
Author: Richard Biener <[email protected]>
Date:   Wed Jun 24 09:36:49 2026 +0200

    tree-optimization/110743 - expand RMW uninit detection
    
    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.

Diff:
---
 gcc/testsuite/gcc.dg/uninit-pr110743-2.c | 19 +++++++++++++++++++
 gcc/tree-ssa-uninit.cc                   |  7 +++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/uninit-pr110743-2.c 
b/gcc/testsuite/gcc.dg/uninit-pr110743-2.c
new file mode 100644
index 000000000000..8119bb49bbf8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr110743-2.c
@@ -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);
+}
diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc
index 107ed21e10b8..1072e1e270bb 100644
--- a/gcc/tree-ssa-uninit.cc
+++ b/gcc/tree-ssa-uninit.cc
@@ -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),

Reply via email to