symtab: Fix init and fini priority to reset to default [PR120030]

Right now if try to reset the priority of a constructor to the
default (65535), there is an ICE.
To fix this the assert is wrong and intead we should check
if the priority is already the default if not then we should
just update it.

Bootstrapped and tested on x86_64-linux-gnu.

	PR middle-end/120030

gcc/ChangeLog:

	* symtab.cc (symtab_node::set_init_priority): Better
	handle the case of setting the priority back to default.
	(cgraph_node::set_fini_priority): Likewise.

gcc/testsuite/ChangeLog:

	* gcc.dg/constructor-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
This commit is contained in:
Andrew Pinski
2026-03-11 14:41:31 -07:00
parent 7345e4151a
commit 6a1cb23b73
2 changed files with 13 additions and 10 deletions

View File

@@ -1897,11 +1897,9 @@ symtab_node::set_init_priority (priority_type priority)
if (is_a <cgraph_node *> (this))
gcc_assert (DECL_STATIC_CONSTRUCTOR (this->decl));
if (priority == DEFAULT_INIT_PRIORITY)
{
gcc_assert (get_init_priority() == priority);
return;
}
if (priority == DEFAULT_INIT_PRIORITY
&& get_init_priority() == priority)
return;
h = priority_info ();
h->init = priority;
}
@@ -1915,11 +1913,9 @@ cgraph_node::set_fini_priority (priority_type priority)
gcc_assert (DECL_STATIC_DESTRUCTOR (this->decl));
if (priority == DEFAULT_INIT_PRIORITY)
{
gcc_assert (get_fini_priority() == priority);
return;
}
if (priority == DEFAULT_INIT_PRIORITY
&& get_fini_priority() == priority)
return;
h = priority_info ();
h->fini = priority;
}

View File

@@ -0,0 +1,7 @@
/* { dg-do compile { target init_priority } } */
/* { dg-options "" } */
/* PR middle-end/120030 */
void f() __attribute__ ((constructor (140))) __attribute__ ((constructor));
void g() __attribute__ ((destructor (140))) __attribute__ ((destructor));