https://gcc.gnu.org/g:f0eda7b41dfcf0f5d98b840690e8d524eb8c1790

commit r16-5172-gf0eda7b41dfcf0f5d98b840690e8d524eb8c1790
Author: Jason Merrill <[email protected]>
Date:   Sun Nov 9 05:15:00 2025 +0530

    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:
---
 gcc/cp/module.cc | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index da9d29b4b01e..352d42af2ed5 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;
 }

Reply via email to