Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

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 | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 765fcfb6000..1b0d9717b6c 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -17353,11 +17353,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--;
 
@@ -20087,7 +20083,7 @@ post_load_processing ()
        DECL_EXTERNAL (decl) = false;
     }
 
-  cfun = old_cfun;
+  set_cfun (old_cfun);
   current_function_decl = old_cfd;
 }
 

base-commit: 8fad025430b4fded6c9ebbc6bd4fd8ac4e8a2194
-- 
2.51.0

Reply via email to