]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Save target node before parsing optimize options in case it changes.
authorIain Buclaw <ibuclaw@gdcproject.org>
Sun, 3 Oct 2021 13:21:05 +0000 (15:21 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 4 Oct 2021 15:07:29 +0000 (17:07 +0200)
Fixes an ICE seen on PowerPC targets with the attr_optimize*.d tests in
the gdc.dg testsuite.

gcc/d/ChangeLog:

* d-attribs.cc (d_handle_optimize_attribute): Save target node before
calling parse_optimize_options in case it changes.

gcc/d/d-attribs.cc

index 070866020a2c979220930323f6cb13b6cce6351b..d81b7d122f7470f4c3c1ff43793aa1a2b5f31a2a 100644 (file)
@@ -896,6 +896,8 @@ d_handle_optimize_attribute (tree *node, tree name, tree args, int,
 
       /* Save current options.  */
       cl_optimization_save (&cur_opts, &global_options, &global_options_set);
+      tree prev_target_node = build_target_option_node (&global_options,
+                                                       &global_options_set);
 
       /* If we previously had some optimization options, use them as the
         default.  */
@@ -914,10 +916,16 @@ d_handle_optimize_attribute (tree *node, tree name, tree args, int,
       parse_optimize_options (args);
       DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
        = build_optimization_node (&global_options, &global_options_set);
+      tree target_node = build_target_option_node (&global_options,
+                                                  &global_options_set);
+      if (prev_target_node != target_node)
+       DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
 
       /* Restore current options.  */
       cl_optimization_restore (&global_options, &global_options_set,
                               &cur_opts);
+      cl_target_option_restore (&global_options, &global_options_set,
+                               TREE_TARGET_OPTION (prev_target_node));
       if (saved_global_options != NULL)
        {
          cl_optimization_compare (saved_global_options, &global_options);