diff mbox series

Add missing varasm DECL_P check.

Message ID 20201210030931.11570-1-jimw@sifive.com
State New
Headers show
Series Add missing varasm DECL_P check. | expand

Commit Message

Jim Wilson Dec. 10, 2020, 3:09 a.m. UTC
This fixes a riscv64-linux bootstrap failure.

get_constant_section calls the select_section target hook, and select_section
calls get_named_section which calls get_section.  So it is possible to have
a constant not a decl in both of these functions.  They already call DECL_P
checks everywhere except for the new code HJ recently added.  This adds the
missing DECL_P check.

Verified with a riscv64-linux bootstrap.

OK?

Jim
---
 gcc/varasm.c | 1 +
 1 file changed, 1 insertion(+)

Comments

H.J. Lu Dec. 10, 2020, 3:14 a.m. UTC | #1
On Wed, Dec 9, 2020 at 7:10 PM Jim Wilson <jimw@sifive.com> wrote:
>
> This fixes a riscv64-linux bootstrap failure.
>
> get_constant_section calls the select_section target hook, and select_section
> calls get_named_section which calls get_section.  So it is possible to have
> a constant not a decl in both of these functions.  They already call DECL_P
> checks everywhere except for the new code HJ recently added.  This adds the
> missing DECL_P check.
>
> Verified with a riscv64-linux bootstrap.
>
> OK?
>
> Jim
> ---
>  gcc/varasm.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gcc/varasm.c b/gcc/varasm.c
> index 0fac3688828..5b2e123b0da 100644
> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -294,6 +294,7 @@ get_section (const char *name, unsigned int flags, tree decl,
>    flags |= SECTION_NAMED;
>    if (HAVE_GAS_SHF_GNU_RETAIN
>        && decl != nullptr
> +      && DECL_P (decl)
>        && DECL_PRESERVE_P (decl))
>      flags |= SECTION_RETAIN;
>    if (*slot == NULL)
> --
> 2.17.1
>

 A testcase?
Jim Wilson Dec. 10, 2020, 6:17 a.m. UTC | #2
On Wed, Dec 9, 2020 at 7:14 PM H.J. Lu <hjl.tools@gmail.com> wrote:

>  A testcase?
>

A testcase requires the RISC-V select_section target hook, so it isn't
going to be very useful.  I don't see any other linux targets that have
this hook defined.  Just a few embedded targets.  The testcase
is libgfortran/generated/product_c4.c.  I haven't tried to reduce it.  It
fails both for a native build and a cross build.

Jim
Richard Sandiford Dec. 10, 2020, 10:36 a.m. UTC | #3
Jim Wilson <jimw@sifive.com> writes:
> This fixes a riscv64-linux bootstrap failure.
>
> get_constant_section calls the select_section target hook, and select_section
> calls get_named_section which calls get_section.  So it is possible to have
> a constant not a decl in both of these functions.  They already call DECL_P
> checks everywhere except for the new code HJ recently added.  This adds the
> missing DECL_P check.
>
> Verified with a riscv64-linux bootstrap.
>
> OK?

OK, thanks.  (And yeah, I agree a testcase isn't needed for bootstrap fixes.)

Richard

>
> Jim
> ---
>  gcc/varasm.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gcc/varasm.c b/gcc/varasm.c
> index 0fac3688828..5b2e123b0da 100644
> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -294,6 +294,7 @@ get_section (const char *name, unsigned int flags, tree decl,
>    flags |= SECTION_NAMED;
>    if (HAVE_GAS_SHF_GNU_RETAIN
>        && decl != nullptr
> +      && DECL_P (decl)
>        && DECL_PRESERVE_P (decl))
>      flags |= SECTION_RETAIN;
>    if (*slot == NULL)
diff mbox series

Patch

diff --git a/gcc/varasm.c b/gcc/varasm.c
index 0fac3688828..5b2e123b0da 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -294,6 +294,7 @@  get_section (const char *name, unsigned int flags, tree decl,
   flags |= SECTION_NAMED;
   if (HAVE_GAS_SHF_GNU_RETAIN
       && decl != nullptr
+      && DECL_P (decl)
       && DECL_PRESERVE_P (decl))
     flags |= SECTION_RETAIN;
   if (*slot == NULL)