Avoid ICE on alias + section attributes on different redeclarations (PR c/90760)

Message ID 20190611072342.GI19695@tucnak
State New
Headers show
Series
  • Avoid ICE on alias + section attributes on different redeclarations (PR c/90760)
Related show

Commit Message

Jakub Jelinek June 11, 2019, 7:23 a.m.
Hi!

On the following testcase, we handle the case where both attributes
are on the same decl (as varpool_node::alias isn't set yet), by setting the
section even on the alias and then diagnosing if it is different from the
target's section (would succeed with bar having baz section attribute).
If the alias and section attributes are on different declarations of the
same function, we ICE, as set_section asserts this->alias is not set,
but during cp_finish_decl it is.  My understanding is the problem the assert
wants to avoid is when the varpool node is already analyzed, aliases are
created and copied from the target to the aliases, but before that we can do
what we do if all the attributes are on the same decl.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-06-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/90760
	* symtab.c (symtab_node::set_section): Allow being called on aliases
	as long as they aren't analyzed yet.

	* gcc.dg/pr90760.c: New test.


	Jakub

Comments

Jeff Law June 11, 2019, 7:56 p.m. | #1
On 6/11/19 1:23 AM, Jakub Jelinek wrote:
> Hi!

> 

> On the following testcase, we handle the case where both attributes

> are on the same decl (as varpool_node::alias isn't set yet), by setting the

> section even on the alias and then diagnosing if it is different from the

> target's section (would succeed with bar having baz section attribute).

> If the alias and section attributes are on different declarations of the

> same function, we ICE, as set_section asserts this->alias is not set,

> but during cp_finish_decl it is.  My understanding is the problem the assert

> wants to avoid is when the varpool node is already analyzed, aliases are

> created and copied from the target to the aliases, but before that we can do

> what we do if all the attributes are on the same decl.

> 

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

> 

> 2019-06-11  Jakub Jelinek  <jakub@redhat.com>

> 

> 	PR c/90760

> 	* symtab.c (symtab_node::set_section): Allow being called on aliases

> 	as long as they aren't analyzed yet.

> 

> 	* gcc.dg/pr90760.c: New test.

OK
jeff

Patch

--- gcc/symtab.c.jj	2019-06-11 09:12:36.366555191 +0200
+++ gcc/symtab.c	2019-06-11 09:13:16.208922538 +0200
@@ -1583,7 +1583,7 @@  symtab_node::set_section (symtab_node *n
 void
 symtab_node::set_section (const char *section)
 {
-  gcc_assert (!this->alias);
+  gcc_assert (!this->alias || !this->analyzed);
   call_for_symbol_and_aliases
     (symtab_node::set_section, const_cast<char *>(section), true);
 }
--- gcc/testsuite/gcc.dg/pr90760.c.jj	2019-06-11 09:17:19.819054263 +0200
+++ gcc/testsuite/gcc.dg/pr90760.c	2019-06-11 09:17:12.034177879 +0200
@@ -0,0 +1,8 @@ 
+/* PR c/90760 */
+/* { dg-do compile } */
+/* { dg-require-named-sections "" } */
+
+void bar (void) {}
+void foo (void) __attribute__ ((alias ("bar")));	/* { dg-error "section of alias 'foo' must match section of its target" } */
+void foo (void) __attribute__ ((section ("baz")));
+void qux (void) __attribute__ ((alias ("bar"), section ("baz")));	/* { dg-error "section of alias 'qux' must match section of its target" } */