]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix modref_eaf_analysis::analyze_ssa_name handling of values dereferenced to function...
authorJan Hubicka <hubicka@ucw.cz>
Mon, 22 Jul 2024 16:08:08 +0000 (18:08 +0200)
committerSam James <sam@gentoo.org>
Mon, 14 Oct 2024 19:52:39 +0000 (20:52 +0100)
modref_eaf_analysis::analyze_ssa_name misinterprets EAF flags.  If dereferenced
parameter is passed (to map_iterator in the testcase) it can be returned
indirectly which in turn makes it to escape into the next function call.

PR ipa/115033

gcc/ChangeLog:

* ipa-modref.cc (modref_eaf_analysis::analyze_ssa_name): Fix checking of
EAF flags when analysing values dereferenced as function parameters.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/pr115033.c: New test.

(cherry picked from commit cf8ffc58aad3127031c229a75cc4b99c8ace25e0)

gcc/ipa-modref.cc
gcc/testsuite/gcc.c-torture/execute/pr115033.c [new file with mode: 0644]

index c3e3fd50d1736784d63c528be0a35bf1504c5c4e..bcd9b49fe63181f2ac89397812d6d65ec25e711b 100644 (file)
@@ -2568,8 +2568,10 @@ modref_eaf_analysis::analyze_ssa_name (tree name, bool deferred)
                    int call_flags = deref_flags
                            (gimple_call_arg_flags (call, i), ignore_stores);
                    if (!ignore_retval && !(call_flags & EAF_UNUSED)
-                       && !(call_flags & EAF_NOT_RETURNED_DIRECTLY)
-                       && !(call_flags & EAF_NOT_RETURNED_INDIRECTLY))
+                       && (call_flags & (EAF_NOT_RETURNED_DIRECTLY
+                                         | EAF_NOT_RETURNED_INDIRECTLY))
+                           != (EAF_NOT_RETURNED_DIRECTLY
+                               | EAF_NOT_RETURNED_INDIRECTLY))
                      merge_call_lhs_flags (call, i, name, false, true);
                    if (ecf_flags & (ECF_CONST | ECF_NOVOPS))
                      m_lattice[index].merge_direct_load ();
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr115033.c b/gcc/testsuite/gcc.c-torture/execute/pr115033.c
new file mode 100644 (file)
index 0000000..3e79367
--- /dev/null
@@ -0,0 +1,35 @@
+
+typedef struct func
+{
+  int *a;
+}func;
+__attribute__((noinline))
+void ff(struct func *t)
+{
+  *(t->a) = 0;
+}
+
+
+typedef struct mapped_iterator {
+  func F;
+}mapped_iterator;
+
+__attribute__((noinline))
+mapped_iterator map_iterator(func F) {
+  mapped_iterator t = {F};
+  return t;
+}
+
+void map_to_vector(func *F) {
+  mapped_iterator t = map_iterator(*F);
+  ff(&t.F);
+}
+int main() {
+  int resultIsStatic = 1;
+  func t ={&resultIsStatic};
+  map_to_vector(&t);
+
+  if (resultIsStatic)
+    __builtin_trap();
+  __builtin_exit(0);
+}