[obvious] options: Properly compare string options.

Message ID 89a60c1b-7ad0-3c29-46e9-7ca01205cfa4@suse.cz
State New
Headers show
Series
  • [obvious] options: Properly compare string options.
Related show

Commit Message

Martin Liška June 24, 2020, 7:23 a.m.
For string types we must emit more complex code than simple pointer comparison.
It's pretty much the same what we emit for cl_optimization_print_diff.
I'm going to install it as obvious.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Martin

gcc/ChangeLog:

	* optc-save-gen.awk: Compare string options in cl_optimization_compare
	by strcmp.
---
  gcc/optc-save-gen.awk | 20 ++++++++++++++++----
  1 file changed, 16 insertions(+), 4 deletions(-)

-- 
2.27.0

Patch

diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 1b010085b75..760bf26721a 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -126,8 +126,10 @@  for (i = 0; i < n_opts; i++) {
  			else if (otype ~ "^signed +char *$")
  				var_opt_range[name] = "-128, 127"
  		}
-		else if (otype ~ "^const char \\**$")
+		else if (otype ~ "^const char \\**$") {
  			var_opt_string[n_opt_string++] = name;
+			string_options_names[name]++
+		}
  		else
  			var_opt_other[n_opt_other++] = name;
  	}
@@ -382,8 +384,10 @@  if (have_save) {
  				if (otype == var_type(flags[i]))
  					var_target_range[name] = ""
  			}
-			else if (otype ~ "^const char \\**$")
+			else if (otype ~ "^const char \\**$") {
  				var_target_string[n_target_string++] = name;
+				string_options_names[name]++
+			}
  			else
  				var_target_other[n_target_other++] = name;
  		}
@@ -966,8 +970,16 @@  for (i = 0; i < n_opts; i++) {
  		continue;
  	checked_options[name]++
  
-	print "  if (ptr1->x_" name " != ptr2->x_" name ")"
-	print "    internal_error (\"%<global_options%> are modified in local context\");";
+	if (name in string_options_names) {
+	  print "  if (ptr1->x_" name " != ptr2->x_" name "";
+	  print "      && (!ptr1->x_" name" || !ptr2->x_" name
+	  print "          || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
+	  print "    internal_error (\"%<global_options%> are modified in local context\");";
+	}
+	else {
+	  print "  if (ptr1->x_" name " != ptr2->x_" name ")"
+	  print "    internal_error (\"%<global_options%> are modified in local context\");";
+	}
  }
  
  print "}";