The following avoids ICEing on a indirect calls with a fnspec
in modref analysis.

Bootstrap & regtest running on x86_64-unknown-linux-gnu - OK?

Thanks,
Richard.

2021-01-19  Richard Biener  <rguent...@suse.de>

        PR ipa/98330
        * ipa-modref.c (analyze_stmt): Only record a summary for a
        direct call.

        * g++.dg/pr98330.C: New testcase.
        * gcc.dg/pr98330.c: Likewise.
---
 gcc/ipa-modref.c               | 12 +++++++-----
 gcc/testsuite/g++.dg/pr98330.C |  7 +++++++
 gcc/testsuite/gcc.dg/pr98330.c |  7 +++++++
 3 files changed, 21 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr98330.C
 create mode 100644 gcc/testsuite/gcc.dg/pr98330.c

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index 74ad876cf58..8a5669c7f9b 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -1247,11 +1247,13 @@ analyze_stmt (modref_summary *summary, 
modref_summary_lto *summary_lto,
            && (!fnspec.global_memory_read_p ()
                || !fnspec.global_memory_written_p ()))
          {
-           fnspec_summaries->get_create
-                (cgraph_node::get (current_function_decl)->get_edge (stmt))
-                       ->fnspec = xstrdup (fnspec.get_str ());
-           if (dump_file)
-             fprintf (dump_file, "  Recorded fnspec %s\n", fnspec.get_str ());
+           cgraph_edge *e = cgraph_node::get (current_function_decl)->get_edge 
(stmt);
+           if (e->callee)
+             {
+               fnspec_summaries->get_create (e)->fnspec = xstrdup 
(fnspec.get_str ());
+               if (dump_file)
+                 fprintf (dump_file, "  Recorded fnspec %s\n", fnspec.get_str 
());
+             }
          }
       }
      return true;
diff --git a/gcc/testsuite/g++.dg/pr98330.C b/gcc/testsuite/g++.dg/pr98330.C
new file mode 100644
index 00000000000..08bf77b5c4b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr98330.C
@@ -0,0 +1,7 @@
+// { dg-do compile }
+// { dg-options -O2 }
+
+float f (float x)
+{
+  return __builtin_pow[1] (x, 2); // { dg-warning "pointer to a function used 
in arithmetic" }
+}
diff --git a/gcc/testsuite/gcc.dg/pr98330.c b/gcc/testsuite/gcc.dg/pr98330.c
new file mode 100644
index 00000000000..bc68a6fa214
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr98330.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+float f (__typeof (__builtin_pow) fn, float x)
+{
+  return fn (x, 2);
+}
-- 
2.26.2

Reply via email to