diff mbox series

x86: Check FUNCTION_DECL before calling cgraph_node::get

Message ID 20211207131536.288038-1-hjl.tools@gmail.com
State New
Headers show
Series x86: Check FUNCTION_DECL before calling cgraph_node::get | expand

Commit Message

H.J. Lu Dec. 7, 2021, 1:15 p.m. UTC
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          |  3 ++-
 gcc/testsuite/gcc.dg/pr103594.c | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr103594.c

Comments

Uros Bizjak Dec. 7, 2021, 1:23 p.m. UTC | #1
On Tue, Dec 7, 2021 at 2:15 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> 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.

OK.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386.c          |  3 ++-
>  gcc/testsuite/gcc.dg/pr103594.c | 14 ++++++++++++++
>  2 files changed, 16 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.dg/pr103594.c
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 52547b0f057..f1e41fd55f9 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -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
> index 00000000000..0eae239eea0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr103594.c
> @@ -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) ();
> +}
> --
> 2.33.1
>
diff mbox series

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 52547b0f057..f1e41fd55f9 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -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
index 00000000000..0eae239eea0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103594.c
@@ -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) ();
+}