[PATCH] varasm: Fix ICE with -fsyntax-only [PR99035]

Richard Biener rguenther@suse.de
Wed Feb 10 15:58:11 GMT 2021


On Wed, 10 Feb 2021, Jakub Jelinek wrote:

> Hi!
> 
> My FE change from 2 years ago uses TREE_ASM_WRITTEN in -fsyntax-only
> mode more aggressively to avoid "expanding" functions multiple times.
> With -fsyntax-only nothing is really expanded, so I think it is acceptable
> to adjust the assert and allow declare_weak at any time, with -fsyntax-only
> we know it is during parsing only anyway.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK if you add a comment.

Thanks,
Richrd.

> 2021-02-10  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/99035
> 	* varasm.c (declare_weak): For -fsyntax-only, allow even
> 	TREE_ASM_WRITTEN function decls.
> 
> 	* g++.dg/ext/weak6.C: New test.
> 
> --- gcc/varasm.c.jj	2021-01-04 10:25:38.824233926 +0100
> +++ gcc/varasm.c	2021-02-10 13:18:29.278890110 +0100
> @@ -5927,7 +5927,9 @@ merge_weak (tree newdecl, tree olddecl)
>  void
>  declare_weak (tree decl)
>  {
> -  gcc_assert (TREE_CODE (decl) != FUNCTION_DECL || !TREE_ASM_WRITTEN (decl));
> +  gcc_assert (TREE_CODE (decl) != FUNCTION_DECL
> +	      || !TREE_ASM_WRITTEN (decl)
> +	      || flag_syntax_only);
>    if (! TREE_PUBLIC (decl))
>      {
>        error ("weak declaration of %q+D must be public", decl);
> --- gcc/testsuite/g++.dg/ext/weak6.C.jj	2021-02-10 13:26:52.862203677 +0100
> +++ gcc/testsuite/g++.dg/ext/weak6.C	2021-02-10 13:26:46.439276213 +0100
> @@ -0,0 +1,8 @@
> +// PR c++/99035
> +// { dg-do compile }
> +// { dg-require-weak "" }
> +// { dg-options "-fsyntax-only" }
> +
> +extern void * foo (void);
> +void * foo (void) { return (void *)foo; }
> +#pragma weak foo
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)


More information about the Gcc-patches mailing list