From 6a1cb23b73dad5bab5b8cabc8102f375dc285c52 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Wed, 11 Mar 2026 14:41:31 -0700 Subject: [PATCH] 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 --- gcc/symtab.cc | 16 ++++++---------- gcc/testsuite/gcc.dg/constructor-2.c | 7 +++++++ 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/constructor-2.c diff --git a/gcc/symtab.cc b/gcc/symtab.cc index acb1cd5b36f..c8c67c0ee15 100644 --- a/gcc/symtab.cc +++ b/gcc/symtab.cc @@ -1897,11 +1897,9 @@ symtab_node::set_init_priority (priority_type priority) if (is_a (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; } diff --git a/gcc/testsuite/gcc.dg/constructor-2.c b/gcc/testsuite/gcc.dg/constructor-2.c new file mode 100644 index 00000000000..62ac041ae99 --- /dev/null +++ b/gcc/testsuite/gcc.dg/constructor-2.c @@ -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));