x86: Check FUNCTION_DECL before calling cgraph_node::get
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 7 Dec 2021 13:09:34 +0000 (05:09 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 7 Dec 2021 13:24:47 +0000 (05:24 -0800)
gcc/

PR target/103594
* config/i386/i386.c (ix86_call_use_plt_p): Check FUNCTION_DECL
before calling cgraph_node::get.

gcc/testsuite/

PR target/103594
* gcc.dg/pr103594.c: New test.

gcc/config/i386/i386.c
gcc/testsuite/gcc.dg/pr103594.c [new file with mode: 0644]

index 52547b0..f1e41fd 100644 (file)
@@ -15987,7 +15987,8 @@ ix86_call_use_plt_p (rtx call_op)
 {
   if (SYMBOL_REF_LOCAL_P (call_op))
     {
-      if (SYMBOL_REF_DECL (call_op))
+      if (SYMBOL_REF_DECL (call_op)
+         && TREE_CODE (SYMBOL_REF_DECL (call_op)) == FUNCTION_DECL)
        {
          /* NB: All ifunc functions must be called via PLT.  */
          cgraph_node *node
diff --git a/gcc/testsuite/gcc.dg/pr103594.c b/gcc/testsuite/gcc.dg/pr103594.c
new file mode 100644 (file)
index 0000000..0eae239
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-O1 -fpic" } */
+
+int regex_subst(void)
+{
+  const void *subst = "";
+  return (*(int (*)(int))subst) (0);
+}
+
+int foobar (void)
+{
+  int x;
+  return (*(int (*)(void))&x) ();
+}