On 3/19/20 9:32 AM, Martin Liška wrote:
On 3/19/20 10:09 AM, Jakub Jelinek wrote:
I mean, optimize for the !flag_checking case...
Sure, I transformed both situations into heap memory allocation.
In gcc/c-family/c-attribs.c I faced maybe uninitialized warning when
I only assigned (and checked) the variable in flag_checking context.
I was mostly just curious about what was being checked and how so
I might be misunderstanding something but it looks to me like
the code generated by the loop below will be a very long series
(of hundreds?) of if statements, each doing the same thing but
each hardcoding different options names. If that's correct, is
there an easy way to turn that repetitive series into a loop to
keep code (and string) size growth to a minimum?
Also, since the function prints output and the caller then aborts
on failure, would calling internal_error for the first mismatch
instead be more in keeping with how internal errors with additional
output are reported?
One last question/suggestion: if the efficiency of the checking is
at all a concern, would calling memcmp on the arrays first and only
looping to find the position of the mismatch, be viable? (I have no
idea if changes to some of the options are acceptable; if they are
this wouldn't work).
Martin
PS Since the function doesn't modify the option arrays it could
declare them const.
diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk
index 856a69168a5..586213da3d3 100644
--- a/gcc/opth-gen.awk
+++ b/gcc/opth-gen.awk
@@ -119,6 +119,41 @@ print "#endif"
print "#endif"
print ""
+print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) &&
!defined(IN_RTS)"
+print "#ifndef GENERATOR_FILE"
+print "static inline bool gcc_options_check (gcc_options *ptr1,
gcc_options *ptr2)"
+print "{"
+print " bool result = true;"
+
+# 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 " {"
+ print " if (result)"
+ print " fprintf (stderr, \"Error: global_options are modified in
local context:\\n\");"
+ print " fprintf (stderr, \" " name " (%ld/%ld)\\n\", (long
int)ptr1->x_" name ", (long int)ptr2->x_" name ");"
+ print " result = false;"
+ print " }"
+}
+
+print " return result;"
+print "}"
+print "#endif"
+print "#endif"
+
# All of the optimization switches gathered together so they can be
saved and restored.
# This will allow attribute((cold)) to turn on space optimization.