]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: use set_cfun
authorJason Merrill <jason@redhat.com>
Sat, 8 Nov 2025 23:45:00 +0000 (05:15 +0530)
committerJason Merrill <jason@redhat.com>
Tue, 11 Nov 2025 16:20:46 +0000 (21:50 +0530)
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.

gcc/cp/module.cc

index da9d29b4b01efa8da5c5ff2a1cf10a76dae72ec6..352d42af2ed5e1468b4614129b4d24d49cb84618 100644 (file)
@@ -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;
 }