]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add gcc_assert that &global_options are not dirty modified.
authorMartin Liska <mliska@suse.cz>
Tue, 10 Dec 2019 18:41:08 +0000 (19:41 +0100)
committerMartin Liska <mliska@suse.cz>
Wed, 10 Jun 2020 08:04:14 +0000 (10:04 +0200)
gcc/ChangeLog:

2020-03-20  Martin Liska  <mliska@suse.cz>

PR tree-optimization/92860
* optc-save-gen.awk: Generate new function cl_optimization_compare.
* opth-gen.awk: Generate declaration of the function.

gcc/c-family/ChangeLog:

2020-03-20  Martin Liska  <mliska@suse.cz>

PR tree-optimization/92860
* c-attribs.c (handle_optimize_attribute):
Save global options and compare it after parsing of function
attribute.
* c-pragma.c (opt_stack::saved_global_options): New field.
(handle_pragma_push_options): Save global_options.
(handle_pragma_pop_options): Compare them after pop.

gcc/c-family/c-attribs.c
gcc/c-family/c-pragma.c
gcc/optc-save-gen.awk
gcc/opth-gen.awk

index 193c4cd7cd0de75553c1e4a31592a627b5db06e7..372148315389db6671dfd943fd1a68670fcb1cbc 100644 (file)
@@ -4452,6 +4452,13 @@ handle_optimize_attribute (tree *node, tree name, tree args,
 
       /* If we previously had some optimization options, use them as the
         default.  */
+      gcc_options *saved_global_options = NULL;
+      if (flag_checking)
+       {
+         saved_global_options = XNEW (gcc_options);
+         *saved_global_options = global_options;
+       }
+
       if (old_opts)
        cl_optimization_restore (&global_options,
                                 TREE_OPTIMIZATION (old_opts));
@@ -4463,6 +4470,11 @@ handle_optimize_attribute (tree *node, tree name, tree args,
 
       /* Restore current options.  */
       cl_optimization_restore (&global_options, &cur_opts);
+      if (saved_global_options != NULL)
+       {
+         cl_optimization_compare (saved_global_options, &global_options);
+         free (saved_global_options);
+       }
     }
 
   return NULL_TREE;
index 7c35741745bd21879ecfb583a3a544da50baf0ac..e3169e68fb643031302b39b76945aa0805b91b66 100644 (file)
@@ -1003,6 +1003,7 @@ struct GTY(()) opt_stack {
   tree target_strings;
   tree optimize_binary;
   tree optimize_strings;
+  gcc_options * GTY ((skip)) saved_global_options;
 };
 
 static GTY(()) struct opt_stack * options_stack;
@@ -1028,6 +1029,11 @@ handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
   options_stack = p;
 
   /* Save optimization and target flags in binary format.  */
+  if (flag_checking)
+    {
+      p->saved_global_options = XNEW (gcc_options);
+      *p->saved_global_options = global_options;
+    }
   p->optimize_binary = build_optimization_node (&global_options);
   p->target_binary = build_target_option_node (&global_options);
 
@@ -1079,6 +1085,11 @@ handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
                                      p->optimize_binary);
       optimization_current_node = p->optimize_binary;
     }
+  if (flag_checking)
+    {
+      cl_optimization_compare (p->saved_global_options, &global_options);
+      free (p->saved_global_options);
+    }
 
   current_target_pragma = p->target_strings;
   current_optimize_pragma = p->optimize_strings;
index 6033f5198662fda92e372c29c64863390f1ec68c..4a0e5ab64f388c7b2f688d263848d54e6dfc160a 100644 (file)
@@ -945,5 +945,30 @@ for (i = 0; i < n_opt_val; i++) {
              print "    free (const_cast <char *>(ptr->" name"));";
        }
 }
+print "}";
+
+print "void";
+print "cl_optimization_compare (gcc_options *ptr1, gcc_options *ptr2)"
+print "{"
+
+# all these options are mentioned in PR92860
+checked_options["flag_merge_constants"]++
+checked_options["param_max_fields_for_field_sensitive"]++
+checked_options["flag_omit_frame_pointer"]++
+checked_options["unroll_only_small_loops"]++
+
+for (i = 0; i < n_opts; i++) {
+       name = var_name(flags[i]);
+       if (name == "")
+               continue;
+
+       if (name in checked_options)
+               continue;
+       checked_options[name]++
+
+       print "  if (ptr1->x_" name " != ptr2->x_" name ")"
+       print "    internal_error (\"Error: global_options are modified in local context\\n\");";
+}
+
 print "}";
 }
index 856a69168a5a4623eccdb6fd93e3fbb910640f39..472fd59141352d3269422f656d780529a2bdd459 100644 (file)
@@ -318,6 +318,9 @@ print "";
 print "/* Free heap memory used by optimization options.  */";
 print "extern void cl_optimization_option_free (cl_optimization *ptr1);"
 print "";
+print "/* Compare and report difference for a part of cl_optimization options.  */";
+print "extern void cl_optimization_compare (gcc_options *ptr1, gcc_options *ptr2);";
+print "";
 print "/* Generator files may not have access to location_t, and don't need these.  */"
 print "#if defined(UNKNOWN_LOCATION)"
 print "bool                                                                  "