From: Jason Merrill Date: Sat, 8 Nov 2025 23:45:00 +0000 (+0530) Subject: c++/modules: use set_cfun X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0eda7b41dfcf0f5d98b840690e8d524eb8c1790;p=thirdparty%2Fgcc.git c++/modules: use set_cfun Assigning directly to cfun doesn't properly update the target and optimization options for the new function, which causes trouble if we load a function from a module that has different options than the one we were in the middle of when the load happened. This broke the use of #pragma optimize in 23_containers/array/iterators/begin_end.cc. Nathan's comment in module.cc complained about the API doing too much, but set_cfun seems to me to be exactly what we want here. gcc/cp/ChangeLog: * module.cc (module_state::read_cluster): Use set_cfun. (post_load_processing): Likewise. --- diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index da9d29b4b01..352d42af2ed 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -17346,11 +17346,7 @@ module_state::read_cluster (unsigned snum) } } - /* Look, function.cc's interface to cfun does too much for us, we - just need to restore the old value. I do not want to go - redesigning that API right now. */ -#undef cfun - cfun = old_cfun; + set_cfun (old_cfun); current_function_decl = old_cfd; comparing_dependent_aliases--; @@ -20080,7 +20076,7 @@ post_load_processing () DECL_EXTERNAL (decl) = false; } - cfun = old_cfun; + set_cfun (old_cfun); current_function_decl = old_cfd; }