[RFC,5/7] Fix unhelpful messages for disabled options.

Message ID 5f83621c703c41b79fbc26b4b41d28f3@MTKMBS62N1.mediatek.inc
State New
Headers
Series nanoMIPS port |

Commit Message

Dragan Mladjenovic Sept. 26, 2021, 1:25 p.m. UTC
  Firstly, the option handling was building suggestions without checking
if an option is disabled.  This could have caused other unhelpful
messages for other mistyped options.

Secondly, the key issue here appears to be the lack of CL_JOINED flag
for the false 'Condition' i.e. an option is disabled but other flags are
zeroed out too.  This caused find_opt() not to return the right index
to an option e.g. for -mabi= we would expect OPT_mabi_ rather than
OPT_SPECIAL_unknown, hence, the option did not appear to be correctly
marked as disabled.  The patch aims to retain the extra flag but to keep
an option as disabled.  I do not see any fallout with this, -m<opt>=
are now rejected on the command line and not printed with --target-help.

gcc/ChangeLog:

	* opt-suggestions.c (option_proposer::build_option_suggestions):
	Ignore disabled options.
	* opts.c (print_filtered_help): Likewise.
	* optc-gen.awk: Preserve flags in both cases.

gcc/testsuite/ChangeLog:

	* gcc.target/nanomips/nanomips-err-mabi32.c: New test.
---
 gcc/opt-suggestions.c                                        | 3 +++
 gcc/optc-gen.awk                                             | 5 +++--
 gcc/opts.c                                                   | 4 ++++
 .../gcc.target/nanomips/nanomips-err-mabi32.c (new)          | 4 ++++
 4 files changed, 14 insertions(+), 2 deletions(-)
 4 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/nanomips/nanomips-err-mabi32.c
  

Patch

diff --git a/gcc/opt-suggestions.c b/gcc/opt-suggestions.c
index 5c36fc8cc8c..03bccd5379f 100644
--- a/gcc/opt-suggestions.c
+++ b/gcc/opt-suggestions.c
@@ -108,6 +108,9 @@  option_proposer::build_option_suggestions (const char *prefix)
       switch (i)
 	{
 	default:
+	 /* We don't want to suggest disabled options.  */
+	 if (option->cl_disabled)
+	   continue;
 	  if (option->var_type == CLVC_ENUM)
 	    {
 	      const struct cl_enum *e = &cl_enums[option->var_enum];
diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk
index 77e598efd60..eb725fdb8ce 100644
--- a/gcc/optc-gen.awk
+++ b/gcc/optc-gen.awk
@@ -412,10 +412,11 @@  for (i = 0; i < n_opts; i++) {
 		       "    %s,\n" \
 		       "    0, %s,\n" \
 		       "#else\n" \
-		       "    0,\n" \
+		       "    %s,\n" \
 		       "    1 /* Disabled.  */, %s,\n" \
 		       "#endif\n",
-		       condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
+		       condition, cl_flags, cl_bit_fields,
+		       cl_flags, cl_zero_bit_fields)
 	else
 		printf("    %s,\n" \
 		       "    0, %s,\n",
diff --git a/gcc/opts.c b/gcc/opts.c
index 1d2d22d7a3f..d85fc2adf8a 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1435,6 +1435,10 @@  print_filtered_help (unsigned int include_flags,
 	    continue;
 	}
 
+      /* Skip disabled options.  */
+      if (option->cl_disabled)
+	continue;
+
       /* Skip unwanted switches.  */
       if ((option->flags & exclude_flags) != 0)
 	continue;
diff --git a/gcc/testsuite/gcc.target/nanomips/nanomips-err-mabi32.c b/gcc/testsuite/gcc.target/nanomips/nanomips-err-mabi32.c
new file mode 100644
index 00000000000..1bf233a36e3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nanomips/nanomips-err-mabi32.c
@@ -0,0 +1,4 @@ 
+/* Verify that we get an error for unsupported -mabi=32 option.  */
+/* { dg-additional-options "-mabi=32" } */
+/* { dg-error "not supported by this configuration" "" { target *-*-* } 0 } */
+void foo (void) {}