]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fn-split: Insert new call after clobbers/debug stmt [PR110091]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 21 Feb 2026 22:38:12 +0000 (14:38 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 25 Feb 2026 16:34:28 +0000 (08:34 -0800)
So for function splitting when we outlined the function, we
should keep around the clobbers that were at the begining of
the bb which will be outlined. So change the last stmt
to where we split the bb for where the function call will be
to be after the clobbers.

Note we have to ignore the debug stmts here otherwise you would
get a debug comparison failure.

This also fixes some of the warnings about dangling-pointers because
the clobbers are now correctly handled while function splitting.
The testcases test for the cases where the dangling-pointers pointer
warnings would show up too.

Note only end of storage clobbers in this case.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/110091

gcc/ChangeLog:

* ipa-split.cc (split_function): Split after
the clobbers/debug stmts rather than after the labels.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr110091-1.c: New test.
* gcc.dg/tree-ssa/pr110091-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/ipa-split.cc
gcc/testsuite/gcc.dg/tree-ssa/pr110091-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr110091-2.c [new file with mode: 0644]

index fd1860bf50a59197f5eebce3035a4d1fc09b6134..3185830609daff2058aa6d6197c63f26104e8f68 100644 (file)
@@ -1458,10 +1458,12 @@ split_function (basic_block return_bb, class split_point *split_point,
     dump_function_to_file (node->decl, dump_file, dump_flags);
 
   /* Create the basic block we place call into.  It is the entry basic block
-     split after last label.  */
+     split after last label and after the last eos clobber and debug stmt.  */
   call_bb = split_point->entry_bb;
   for (gimple_stmt_iterator gsi = gsi_start_bb (call_bb); !gsi_end_p (gsi);)
-    if (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL)
+    if (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
+       || gimple_clobber_p (gsi_stmt (gsi), CLOBBER_STORAGE_END)
+       || is_gimple_debug (gsi_stmt (gsi)))
       {
        last_stmt = gsi_stmt (gsi);
        gsi_next (&gsi);
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110091-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr110091-1.c
new file mode 100644 (file)
index 0000000..793a832
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall -O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/110091 */
+/* The clobbers are before the outlined code */
+
+struct tEntry
+{
+    int value;
+};
+int *out;
+
+extern int otherfunc(struct tEntry *);
+extern void anotherfunc(int val);
+
+void bar()
+{
+  {
+    struct tEntry entry1 = { 0 };
+    struct tEntry entry = { 0 };
+
+    if (otherfunc(&entry) != 0)
+      return;
+    if (otherfunc(&entry1) != 0)
+      return;
+    if (out)
+     *out = entry.value; /* { dg-bogus "dangling pointer to" } */
+  }
+  anotherfunc(5);
+}
+
+void foo()
+{
+    bar();
+}
+
+/* There should be 4 CLOBBERs, 2 for entry1 and 2 for entry.  */
+/* { dg-final { scan-tree-dump-times "CLOBBER\\\(eos\\\)" 4 "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110091-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr110091-2.c
new file mode 100644 (file)
index 0000000..d851211
--- /dev/null
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall -O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/110091 */
+/* The clobbers are before the outlined code */
+
+struct tEntry
+{
+    int value;
+};
+int *out;
+
+extern int otherfunc(struct tEntry *);
+extern void anotherfunc(int val);
+
+void bar()
+{
+  {
+    struct tEntry entry = { 0 };
+
+    if (otherfunc(&entry) != 0)
+      return;
+    if (out)
+     *out = entry.value; /* { dg-bogus "dangling pointer to" } */
+  }
+  anotherfunc(5);
+}
+
+void foo()
+{
+    bar();
+}
+
+/* There should be 4 CLOBBERs, 4 for entry; inlined doubles the clobber; return path adds clobber.   */
+/* { dg-final { scan-tree-dump-times "CLOBBER\\\(eos\\\)" 4 "optimized" } } */
+