https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103310
Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 CC| |jason at gcc dot gnu.org Last reconfirmed| |2021-11-18 --- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> --- The C++ front end rejects the testcase with "declared weak after used". We set refuse_visibility_changes under fold's tree_single_nonzero_warnv_p. Changing get_create to get in maybe_nonzero_address makes the C++ compiler accept the testcase, and properly test whether alias is null. This issue seems to go back to Honza's r5-3627, which changed symtab_node::get to symtab_node::get_create in the code that became maybe_nonzero_address, so that we decide early whether a particular function is weak or not. This was done so that constant-evaluation could properly decide that the address of a function is non-null. But it's harmful when we do that for speculative folding; we should only return a definitive answer, and set refuse_visibility_changes, when a constant result is required. It seems we need a way to tell fold that we really want a constant value, have the C++ front end set that for manifestly-constant-evaluated expressions, and only use get_create in that case. But I also guess the issue that the C front end is both optimizing away the test and not setting refuse_visibility_changes is a C front end issue, that it's doing the optimization without involving fold.