public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
@ 2015-12-04 16:37 Jakub Jelinek
  2015-12-04 17:02 ` Bernd Schmidt
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2015-12-04 16:37 UTC (permalink / raw)
  To: Joseph S. Myers, Manuel López-Ibáñez; +Cc: gcc-patches

Hi!

GCC changed recently to disallow -Werror= on W options that don't have
Warning keyword set on them, the following patch fixes 3 spots where
Warning has been unintentionally omitted.  The PR also mentions -Wpsabi,
but I believe -Werror=psabi is not appropriate, because -Wpsabi is not
really a warning, but just set of inform calls, that can't be turned into
error anyway.

While writing a testcase for this, I have noticed that
-Werror=frame-larger-than=65536 is broken, we don't pass the
argument through and it acts as -Werror=frame-larger-than=1.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2015-12-04  Jakub Jelinek  <jakub@redhat.com>

	PR c/48088
	PR c/68657
	* common.opt (Wframe-larger-than=): Add Warning.
	* opts.h (control_warning_option): Add ARG argument.
	* opts-common.c (control_warning_option): Likewise.
	If non-NULL, decode it if needed and pass through
	to handle_generated_option.
	* opts.c (common_handle_option): Adjust control_warning_option
	caller.
	(enable_warning_as_error): Likewise.
c-family/
	* c.opt (Wfloat-conversion, Wsign-conversion): Add Warning.
	* c-pragma.c (handle_pragma_diagnostic): Adjust
	control_warning_option caller.
ada/
	* gcc-interface/trans.c (Pragma_to_gnu): Adjust
	control_warning_option caller.
testsuite/
	* c-c++-common/pr68657-1.c: New test.
	* c-c++-common/pr68657-2.c: New test.
	* c-c++-common/pr68657-3.c: New test.

--- gcc/common.opt.jj	2015-12-02 20:26:59.000000000 +0100
+++ gcc/common.opt	2015-12-04 09:59:10.050125152 +0100
@@ -576,7 +576,7 @@ Common Var(flag_fatal_errors)
 Exit on the first error occurred.
 
 Wframe-larger-than=
-Common RejectNegative Joined UInteger
+Common RejectNegative Joined UInteger Warning
 -Wframe-larger-than=<number>	Warn if a function's stack frame requires more than <number> bytes.
 
 Wfree-nonheap-object
--- gcc/opts.h.jj	2015-11-14 19:35:57.000000000 +0100
+++ gcc/opts.h	2015-12-04 13:29:43.945655448 +0100
@@ -363,7 +363,7 @@ extern void read_cmdline_option (struct
 				 const struct cl_option_handlers *handlers,
 				 diagnostic_context *dc);
 extern void control_warning_option (unsigned int opt_index, int kind,
-				    bool imply, location_t loc,
+				    const char *arg, bool imply, location_t loc,
 				    unsigned int lang_mask,
 				    const struct cl_option_handlers *handlers,
 				    struct gcc_options *opts,
--- gcc/opts-common.c.jj	2015-12-02 20:26:54.000000000 +0100
+++ gcc/opts-common.c	2015-12-04 13:52:56.664401522 +0100
@@ -1332,8 +1332,8 @@ get_option_state (struct gcc_options *op
    used by -Werror= and #pragma GCC diagnostic.  */
 
 void
-control_warning_option (unsigned int opt_index, int kind, bool imply,
-			location_t loc, unsigned int lang_mask,
+control_warning_option (unsigned int opt_index, int kind, const char *arg,
+			bool imply, location_t loc, unsigned int lang_mask,
 			const struct cl_option_handlers *handlers,
 			struct gcc_options *opts,
 			struct gcc_options *opts_set,
@@ -1349,8 +1349,38 @@ control_warning_option (unsigned int opt
     {
       /* -Werror=foo implies -Wfoo.  */
       if (cl_options[opt_index].var_type == CLVC_BOOLEAN)
-	handle_generated_option (opts, opts_set,
-				 opt_index, NULL, 1, lang_mask,
-				 kind, loc, handlers, dc);
+	{
+	  int value = 1;
+
+	  /* If the switch takes an integer, convert it.  */
+	  if (arg && cl_options[opt_index].cl_uinteger)
+	    {
+	      value = integral_argument (arg);
+	      if (value == -1)
+		return;
+	    }
+
+	  /* If the switch takes an enumerated argument, convert it.  */
+	  if (arg && (cl_options[opt_index].var_type == CLVC_ENUM))
+	    {
+	      const struct cl_enum *e
+		= &cl_enums[cl_options[opt_index].var_enum];
+
+	      if (enum_arg_to_value (e->values, arg, &value, lang_mask))
+		{
+		  const char *carg = NULL;
+
+		  if (enum_value_to_arg (e->values, &carg, value, lang_mask))
+		    arg = carg;
+		  gcc_assert (carg != NULL);
+		}
+	      else
+		return;
+	    }
+
+	  handle_generated_option (opts, opts_set,
+				   opt_index, arg, value, lang_mask,
+				   kind, loc, handlers, dc);
+	}
     }
 }
--- gcc/opts.c.jj	2015-11-23 13:29:49.000000000 +0100
+++ gcc/opts.c	2015-12-04 13:39:57.986390792 +0100
@@ -2114,7 +2114,7 @@ common_handle_option (struct gcc_options
 
     case OPT_pedantic_errors:
       dc->pedantic_errors = 1;
-      control_warning_option (OPT_Wpedantic, DK_ERROR, value,
+      control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set,
                               dc);
@@ -2437,8 +2437,11 @@ enable_warning_as_error (const char *arg
   else
     {
       const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
+      const char *arg = NULL;
 
-      control_warning_option (option_index, (int) kind, value,
+      if (cl_options[option_index].flags & CL_JOINED)
+	arg = new_option + cl_options[option_index].opt_len;
+      control_warning_option (option_index, (int) kind, arg, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set, dc);
     }
--- gcc/c-family/c.opt.jj	2015-11-09 13:39:26.000000000 +0100
+++ gcc/c-family/c.opt	2015-12-04 10:06:57.749538643 +0100
@@ -435,7 +435,7 @@ C ObjC RejectNegative Warning Alias(Werr
 This switch is deprecated; use -Werror=implicit-function-declaration instead.
 
 Wfloat-conversion
-C ObjC C++ ObjC++ Var(warn_float_conversion) LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
+C ObjC C++ ObjC++ Var(warn_float_conversion) Warning LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
 Warn for implicit type conversions that cause loss of floating point precision.
 
 Wfloat-equal
@@ -837,7 +837,7 @@ C ObjC C++ ObjC++ EnabledBy(Wextra)
 ;
 
 Wsign-conversion
-C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
+C ObjC C++ ObjC++ Var(warn_sign_conversion) Warning LangEnabledBy(C ObjC,Wconversion)
 Warn for implicit type conversions between signed and unsigned integers.
 
 Wsign-promo
--- gcc/c-family/c-pragma.c.jj	2015-12-02 07:57:20.000000000 +0100
+++ gcc/c-family/c-pragma.c	2015-12-04 13:40:13.934165561 +0100
@@ -814,7 +814,11 @@ handle_pragma_diagnostic(cpp_reader *ARG
 
   struct cl_option_handlers handlers;
   set_default_handlers (&handlers);
-  control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
+  const char *arg = NULL;
+  if (cl_options[option_index].flags & CL_JOINED)
+    arg = option_string + 1 + cl_options[option_index].opt_len;
+  control_warning_option (option_index, (int) kind,
+			  arg, kind != DK_IGNORED,
 			  loc, lang_mask, &handlers,
 			  &global_options, &global_options_set,
 			  global_dc);
--- gcc/ada/gcc-interface/trans.c.jj	2015-12-01 19:48:12.000000000 +0100
+++ gcc/ada/gcc-interface/trans.c	2015-12-04 15:22:38.890268297 +0100
@@ -1441,6 +1441,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 
 	/* This is the same implementation as in the C family of compilers.  */
 	const unsigned int lang_mask = CL_Ada | CL_COMMON;
+	const char *arg = NULL;
 	if (Present (gnat_expr))
 	  {
 	    tree gnu_expr = gnat_to_gnu (gnat_expr);
@@ -1464,12 +1465,14 @@ Pragma_to_gnu (Node_Id gnat_node)
 		post_error ("?-W switch not valid for Ada", gnat_node);
 		break;
 	      }
+	    if (cl_options[option_index].flags & CL_JOINED)
+	      arg = option_string + 1 + cl_options[option_index].opt_len;
 	  }
 	else
 	  option_index = 0;
 
 	set_default_handlers (&handlers);
-	control_warning_option (option_index, (int) kind, imply, location,
+	control_warning_option (option_index, (int) kind, arg, imply, location,
 				lang_mask, &handlers, &global_options,
 				&global_options_set, global_dc);
       }
--- gcc/testsuite/c-c++-common/pr68657-1.c.jj	2015-12-04 13:57:31.826538859 +0100
+++ gcc/testsuite/c-c++-common/pr68657-1.c	2015-12-04 13:59:32.331847233 +0100
@@ -0,0 +1,26 @@
+/* PR c/68657 */
+/* { dg-options "-Werror=sign-conversion -Werror=float-conversion -Werror=frame-larger-than=65536" } */
+
+void
+f1 (void)
+{
+  unsigned int a = -5;	/* { dg-error "negative integer implicitly converted to unsigned type" } */
+  (void) a;
+}
+
+int
+f2 (void)
+{
+  return 3.1f;	/* { dg-error "conversion to 'int' alters 'float' constant value" } */
+}
+
+int f3 (char *);
+
+int
+f4 (void)
+{
+  char buf[131072];
+  return f3 (buf);
+}		/* { dg-error "the frame size of 1\[0-9]* bytes is larger than 65536 bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-2.c.jj	2015-12-04 13:57:31.826538859 +0100
+++ gcc/testsuite/c-c++-common/pr68657-2.c	2015-12-04 13:59:37.715771655 +0100
@@ -0,0 +1,8 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=larger-than=65536" } */
+
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-3.c.jj	2015-12-04 14:09:42.300307466 +0100
+++ gcc/testsuite/c-c++-common/pr68657-3.c	2015-12-04 14:10:18.432816785 +0100
@@ -0,0 +1,13 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+
+#pragma GCC diagnostic error "-Wlarger-than=65536"
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic ignored "-Wlarger-than=65536"
+int c[131072];	/* { dg-bogus "size of 'c' is \[1-9]\[0-9]* bytes" } */
+int d[1024];	/* { dg-bogus "size of 'd' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic warning "-Wlarger-than=65536"
+int e[131072];	/* { dg-warning "size of 'e' is \[1-9]\[0-9]* bytes" } */
+int f[1024];	/* { dg-bogus "size of 'f' is \[1-9]\[0-9]* bytes" } */
+/* { dg-prune-output "treated as errors" } */

	Jakub

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-04 16:37 [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657) Jakub Jelinek
@ 2015-12-04 17:02 ` Bernd Schmidt
  2015-12-04 17:53   ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Bernd Schmidt @ 2015-12-04 17:02 UTC (permalink / raw)
  To: Jakub Jelinek, Joseph S. Myers, Manuel López-Ibáñez
  Cc: gcc-patches

I think marking stuff with Warning as appropriate qualifies as obvious.

On 12/04/2015 05:37 PM, Jakub Jelinek wrote:
> +	  /* If the switch takes an integer, convert it.  */
> +	  if (arg && cl_options[opt_index].cl_uinteger)
> +	    {
> +	      value = integral_argument (arg);
> +	      if (value == -1)
> +		return;
> +	    }

So does this issue an error message anywhere or just silently drop the 
option on the floor if the argument is invalid?

> +	  /* If the switch takes an enumerated argument, convert it.  */
> +	  if (arg && (cl_options[opt_index].var_type == CLVC_ENUM))

Unnecessary parens.


Bernd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-04 17:02 ` Bernd Schmidt
@ 2015-12-04 17:53   ` Jakub Jelinek
  2015-12-04 18:20     ` Manuel López-Ibáñez
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2015-12-04 17:53 UTC (permalink / raw)
  To: Bernd Schmidt
  Cc: Joseph S. Myers, Manuel López-Ibáñez, gcc-patches

On Fri, Dec 04, 2015 at 06:01:58PM +0100, Bernd Schmidt wrote:
> I think marking stuff with Warning as appropriate qualifies as obvious.
> 
> On 12/04/2015 05:37 PM, Jakub Jelinek wrote:
> >+	  /* If the switch takes an integer, convert it.  */
> >+	  if (arg && cl_options[opt_index].cl_uinteger)
> >+	    {
> >+	      value = integral_argument (arg);
> >+	      if (value == -1)
> >+		return;
> >+	    }
> 
> So does this issue an error message anywhere or just silently drop the
> option on the floor if the argument is invalid?

Silently accepted.  Following updated patch accepts e.g.:
-Wlarger-than=5
-Werror=larger-than=5
-Wnormalized=none
-Werror=normalized=none
and rejects (with the same diagnostics between -WXXX=YYY and -Werror=XXX=YYY):
-Wlarger-than=none
-Werror=larger-than=none
-Wlarger-than=
-Werror=larger-than=
-Wnormalized=all
-Werror=normalized=all
-Wnormalized=
-Werror=normalized=
(as examples of Warning UInteger Joined and Warning Enum Joined options).

> >+	  /* If the switch takes an enumerated argument, convert it.  */
> >+	  if (arg && (cl_options[opt_index].var_type == CLVC_ENUM))
> 
> Unnecessary parens.

Fixed.

2015-12-04  Jakub Jelinek  <jakub@redhat.com>

	PR c/48088
	PR c/68657
	* common.opt (Wframe-larger-than=): Add Warning.
	* opts.h (control_warning_option): Add ARG argument.
	* opts-common.c (control_warning_option): Likewise.
	If non-NULL, decode it if needed and pass through
	to handle_generated_option.  Handle CLVC_ENUM like
	CLVC_BOOLEAN.
	* opts.c (common_handle_option): Adjust control_warning_option
	caller.
	(enable_warning_as_error): Likewise.
c-family/
	* c.opt (Wfloat-conversion, Wsign-conversion): Add Warning.
	* c-pragma.c (handle_pragma_diagnostic): Adjust
	control_warning_option caller.
ada/
	* gcc-interface/trans.c (Pragma_to_gnu): Adjust
	control_warning_option caller.
testsuite/
	* c-c++-common/pr68657-1.c: New test.
	* c-c++-common/pr68657-2.c: New test.
	* c-c++-common/pr68657-3.c: New test.

--- gcc/common.opt.jj	2015-12-04 17:19:01.873180339 +0100
+++ gcc/common.opt	2015-12-04 18:07:31.901544973 +0100
@@ -576,7 +576,7 @@ Common Var(flag_fatal_errors)
 Exit on the first error occurred.
 
 Wframe-larger-than=
-Common RejectNegative Joined UInteger
+Common RejectNegative Joined UInteger Warning
 -Wframe-larger-than=<number>	Warn if a function's stack frame requires more than <number> bytes.
 
 Wfree-nonheap-object
--- gcc/opts.h.jj	2015-12-04 17:19:01.939179455 +0100
+++ gcc/opts.h	2015-12-04 18:07:31.901544973 +0100
@@ -363,7 +363,7 @@ extern void read_cmdline_option (struct
 				 const struct cl_option_handlers *handlers,
 				 diagnostic_context *dc);
 extern void control_warning_option (unsigned int opt_index, int kind,
-				    bool imply, location_t loc,
+				    const char *arg, bool imply, location_t loc,
 				    unsigned int lang_mask,
 				    const struct cl_option_handlers *handlers,
 				    struct gcc_options *opts,
--- gcc/opts-common.c.jj	2015-12-04 17:19:01.854180594 +0100
+++ gcc/opts-common.c	2015-12-04 18:44:15.956606061 +0100
@@ -1332,8 +1332,8 @@ get_option_state (struct gcc_options *op
    used by -Werror= and #pragma GCC diagnostic.  */
 
 void
-control_warning_option (unsigned int opt_index, int kind, bool imply,
-			location_t loc, unsigned int lang_mask,
+control_warning_option (unsigned int opt_index, int kind, const char *arg,
+			bool imply, location_t loc, unsigned int lang_mask,
 			const struct cl_option_handlers *handlers,
 			struct gcc_options *opts,
 			struct gcc_options *opts_set,
@@ -1347,10 +1347,89 @@ control_warning_option (unsigned int opt
     diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
   if (imply)
     {
+      const struct cl_option *option = &cl_options[opt_index];
+
       /* -Werror=foo implies -Wfoo.  */
-      if (cl_options[opt_index].var_type == CLVC_BOOLEAN)
-	handle_generated_option (opts, opts_set,
-				 opt_index, NULL, 1, lang_mask,
-				 kind, loc, handlers, dc);
+      if (option->var_type == CLVC_BOOLEAN || option->var_type == CLVC_ENUM)
+	{
+	  int value = 1;
+
+	  if (arg && *arg == '\0' && !option->cl_missing_ok)
+	    arg = NULL;
+
+	  if ((option->flags & CL_JOINED) && arg == NULL)
+	    {
+	      if (option->missing_argument_error)
+		error_at (loc, option->missing_argument_error,
+			  option->opt_text);
+	      else
+		error_at (loc, "missing argument to %qs", option->opt_text);
+	      return;
+	    }
+
+	  /* If the switch takes an integer, convert it.  */
+	  if (arg && option->cl_uinteger)
+	    {
+	      value = integral_argument (arg);
+	      if (value == -1)
+		{
+		  error_at (loc,
+			    "argument to %qs should be a non-negative integer",
+			    option->opt_text);
+		  return;
+		}
+	    }
+
+	  /* If the switch takes an enumerated argument, convert it.  */
+	  if (arg && option->var_type == CLVC_ENUM)
+	    {
+	      const struct cl_enum *e = &cl_enums[option->var_enum];
+
+	      if (enum_arg_to_value (e->values, arg, &value, lang_mask))
+		{
+		  const char *carg = NULL;
+
+		  if (enum_value_to_arg (e->values, &carg, value, lang_mask))
+		    arg = carg;
+		  gcc_assert (carg != NULL);
+		}
+	      else
+		{
+		  unsigned int i;
+		  size_t len;
+		  char *s, *p;
+
+		  if (e->unknown_error)
+		    error_at (loc, e->unknown_error, option->opt_text);
+		  else
+		    error_at (loc, "unrecognized argument in option %qs",
+			      option->opt_text);
+
+		  len = 0;
+		  for (i = 0; e->values[i].arg != NULL; i++)
+		    len += strlen (e->values[i].arg) + 1;
+
+		  s = XALLOCAVEC (char, len);
+		  p = s;
+		  for (i = 0; e->values[i].arg != NULL; i++)
+		    {
+		      if (!enum_arg_ok_for_language (&e->values[i], lang_mask))
+			continue;
+		      size_t arglen = strlen (e->values[i].arg);
+		      memcpy (p, e->values[i].arg, arglen);
+		      p[arglen] = ' ';
+		      p += arglen + 1;
+		    }
+		  p[-1] = 0;
+		  inform (loc, "valid arguments to %qs are: %s",
+			  option->opt_text, s);
+		  return;
+		}
+	    }
+
+	  handle_generated_option (opts, opts_set,
+				   opt_index, arg, value, lang_mask,
+				   kind, loc, handlers, dc);
+	}
     }
 }
--- gcc/opts.c.jj	2015-12-04 17:19:01.901179964 +0100
+++ gcc/opts.c	2015-12-04 18:07:31.902544959 +0100
@@ -2114,7 +2114,7 @@ common_handle_option (struct gcc_options
 
     case OPT_pedantic_errors:
       dc->pedantic_errors = 1;
-      control_warning_option (OPT_Wpedantic, DK_ERROR, value,
+      control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set,
                               dc);
@@ -2437,8 +2437,11 @@ enable_warning_as_error (const char *arg
   else
     {
       const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
+      const char *arg = NULL;
 
-      control_warning_option (option_index, (int) kind, value,
+      if (cl_options[option_index].flags & CL_JOINED)
+	arg = new_option + cl_options[option_index].opt_len;
+      control_warning_option (option_index, (int) kind, arg, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set, dc);
     }
--- gcc/c-family/c.opt.jj	2015-12-04 17:19:02.048177994 +0100
+++ gcc/c-family/c.opt	2015-12-04 18:07:31.902544959 +0100
@@ -435,7 +435,7 @@ C ObjC RejectNegative Warning Alias(Werr
 This switch is deprecated; use -Werror=implicit-function-declaration instead.
 
 Wfloat-conversion
-C ObjC C++ ObjC++ Var(warn_float_conversion) LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
+C ObjC C++ ObjC++ Var(warn_float_conversion) Warning LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
 Warn for implicit type conversions that cause loss of floating point precision.
 
 Wfloat-equal
@@ -837,7 +837,7 @@ C ObjC C++ ObjC++ EnabledBy(Wextra)
 ;
 
 Wsign-conversion
-C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
+C ObjC C++ ObjC++ Var(warn_sign_conversion) Warning LangEnabledBy(C ObjC,Wconversion)
 Warn for implicit type conversions between signed and unsigned integers.
 
 Wsign-promo
--- gcc/c-family/c-pragma.c.jj	2015-12-04 17:19:02.020178369 +0100
+++ gcc/c-family/c-pragma.c	2015-12-04 18:07:31.902544959 +0100
@@ -814,7 +814,11 @@ handle_pragma_diagnostic(cpp_reader *ARG
 
   struct cl_option_handlers handlers;
   set_default_handlers (&handlers);
-  control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
+  const char *arg = NULL;
+  if (cl_options[option_index].flags & CL_JOINED)
+    arg = option_string + 1 + cl_options[option_index].opt_len;
+  control_warning_option (option_index, (int) kind,
+			  arg, kind != DK_IGNORED,
 			  loc, lang_mask, &handlers,
 			  &global_options, &global_options_set,
 			  global_dc);
--- gcc/ada/gcc-interface/trans.c.jj	2015-11-30 13:40:37.408862964 +0100
+++ gcc/ada/gcc-interface/trans.c	2015-12-04 18:07:31.904544931 +0100
@@ -1441,6 +1441,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 
 	/* This is the same implementation as in the C family of compilers.  */
 	const unsigned int lang_mask = CL_Ada | CL_COMMON;
+	const char *arg = NULL;
 	if (Present (gnat_expr))
 	  {
 	    tree gnu_expr = gnat_to_gnu (gnat_expr);
@@ -1464,12 +1465,14 @@ Pragma_to_gnu (Node_Id gnat_node)
 		post_error ("?-W switch not valid for Ada", gnat_node);
 		break;
 	      }
+	    if (cl_options[option_index].flags & CL_JOINED)
+	      arg = option_string + 1 + cl_options[option_index].opt_len;
 	  }
 	else
 	  option_index = 0;
 
 	set_default_handlers (&handlers);
-	control_warning_option (option_index, (int) kind, imply, location,
+	control_warning_option (option_index, (int) kind, arg, imply, location,
 				lang_mask, &handlers, &global_options,
 				&global_options_set, global_dc);
       }
--- gcc/testsuite/c-c++-common/pr68657-1.c.jj	2015-12-04 18:07:31.904544931 +0100
+++ gcc/testsuite/c-c++-common/pr68657-1.c	2015-12-04 18:07:31.904544931 +0100
@@ -0,0 +1,26 @@
+/* PR c/68657 */
+/* { dg-options "-Werror=sign-conversion -Werror=float-conversion -Werror=frame-larger-than=65536" } */
+
+void
+f1 (void)
+{
+  unsigned int a = -5;	/* { dg-error "negative integer implicitly converted to unsigned type" } */
+  (void) a;
+}
+
+int
+f2 (void)
+{
+  return 3.1f;	/* { dg-error "conversion to 'int' alters 'float' constant value" } */
+}
+
+int f3 (char *);
+
+int
+f4 (void)
+{
+  char buf[131072];
+  return f3 (buf);
+}		/* { dg-error "the frame size of 1\[0-9]* bytes is larger than 65536 bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-2.c.jj	2015-12-04 18:07:31.904544931 +0100
+++ gcc/testsuite/c-c++-common/pr68657-2.c	2015-12-04 18:07:31.904544931 +0100
@@ -0,0 +1,8 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=larger-than=65536" } */
+
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-3.c.jj	2015-12-04 18:07:31.904544931 +0100
+++ gcc/testsuite/c-c++-common/pr68657-3.c	2015-12-04 18:07:31.904544931 +0100
@@ -0,0 +1,13 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+
+#pragma GCC diagnostic error "-Wlarger-than=65536"
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic ignored "-Wlarger-than=65536"
+int c[131072];	/* { dg-bogus "size of 'c' is \[1-9]\[0-9]* bytes" } */
+int d[1024];	/* { dg-bogus "size of 'd' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic warning "-Wlarger-than=65536"
+int e[131072];	/* { dg-warning "size of 'e' is \[1-9]\[0-9]* bytes" } */
+int f[1024];	/* { dg-bogus "size of 'f' is \[1-9]\[0-9]* bytes" } */
+/* { dg-prune-output "treated as errors" } */


	Jakub

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-04 17:53   ` Jakub Jelinek
@ 2015-12-04 18:20     ` Manuel López-Ibáñez
  2015-12-04 19:37       ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Manuel López-Ibáñez @ 2015-12-04 18:20 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Bernd Schmidt, Joseph S. Myers, Gcc Patch List

On 4 December 2015 at 17:53, Jakub Jelinek <jakub@redhat.com> wrote:
> +
> +                 if (e->unknown_error)
> +                   error_at (loc, e->unknown_error, option->opt_text);
> +                 else
> +                   error_at (loc, "unrecognized argument in option %qs",
> +                             option->opt_text);

The same code that handles command-line options has:

      if (e->unknown_error)
    error_at (loc, e->unknown_error, decoded->arg);
      else
    error_at (loc, "unrecognized argument in option %qs", opt);

My guess is that the first error_at should use arg instead of
option->opt_text to be equivalent. Of course, ideally, this code would
not be duplicated, but rather merged "somehow".

Cheers,

Manuel.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-04 18:20     ` Manuel López-Ibáñez
@ 2015-12-04 19:37       ` Jakub Jelinek
  2015-12-07 10:24         ` Bernd Schmidt
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2015-12-04 19:37 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: Bernd Schmidt, Joseph S. Myers, Gcc Patch List

On Fri, Dec 04, 2015 at 06:19:19PM +0000, Manuel López-Ibáñez wrote:
> On 4 December 2015 at 17:53, Jakub Jelinek <jakub@redhat.com> wrote:
> > +
> > +                 if (e->unknown_error)
> > +                   error_at (loc, e->unknown_error, option->opt_text);
> > +                 else
> > +                   error_at (loc, "unrecognized argument in option %qs",
> > +                             option->opt_text);
> 
> The same code that handles command-line options has:
> 
>       if (e->unknown_error)
>     error_at (loc, e->unknown_error, decoded->arg);
>       else
>     error_at (loc, "unrecognized argument in option %qs", opt);
> 
> My guess is that the first error_at should use arg instead of
> option->opt_text to be equivalent. Of course, ideally, this code would
> not be duplicated, but rather merged "somehow".

Consider that fixed.  As for duplication, as one operates on
cl_decoded_option and the other not etc., this is harder, plus
the missing and non-int cases are IMHO short enough that it is not worth
trying hard to avoid the duplication.
For the enum case which is larger, it is maybe worth adding
a helper routine for it, which would need probably only
location_t loc, const struct cl_enum *e, const char *opt, unsigned int lang_mask
arguments.  Can try that on Monday.

	Jakub

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-04 19:37       ` Jakub Jelinek
@ 2015-12-07 10:24         ` Bernd Schmidt
  2015-12-07 13:45           ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Bernd Schmidt @ 2015-12-07 10:24 UTC (permalink / raw)
  To: Jakub Jelinek, Manuel López-Ibáñez
  Cc: Joseph S. Myers, Gcc Patch List

On 12/04/2015 08:36 PM, Jakub Jelinek wrote:
> On Fri, Dec 04, 2015 at 06:19:19PM +0000, Manuel López-Ibáñez wrote:
>> My guess is that the first error_at should use arg instead of
>> option->opt_text to be equivalent. Of course, ideally, this code would
>> not be duplicated, but rather merged "somehow".
>
> Consider that fixed.  As for duplication, as one operates on
> cl_decoded_option and the other not etc., this is harder, plus
> the missing and non-int cases are IMHO short enough that it is not worth
> trying hard to avoid the duplication.
> For the enum case which is larger, it is maybe worth adding
> a helper routine for it, which would need probably only
> location_t loc, const struct cl_enum *e, const char *opt, unsigned int lang_mask
> arguments.  Can try that on Monday.

Maybe you can split the error printing code out of read_cmdline_option. 
For the original patch I noticed the duplication but figured it was not 
enough to really worry about, but for the error handling I think we 
should make an effort.


Bernd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-07 10:24         ` Bernd Schmidt
@ 2015-12-07 13:45           ` Jakub Jelinek
  2015-12-07 15:11             ` Bernd Schmidt
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2015-12-07 13:45 UTC (permalink / raw)
  To: Bernd Schmidt
  Cc: Manuel López-Ibáñez, Joseph S. Myers, Gcc Patch List

On Mon, Dec 07, 2015 at 11:24:02AM +0100, Bernd Schmidt wrote:
> On 12/04/2015 08:36 PM, Jakub Jelinek wrote:
> >On Fri, Dec 04, 2015 at 06:19:19PM +0000, Manuel López-Ibáñez wrote:
> >>My guess is that the first error_at should use arg instead of
> >>option->opt_text to be equivalent. Of course, ideally, this code would
> >>not be duplicated, but rather merged "somehow".
> >
> >Consider that fixed.  As for duplication, as one operates on
> >cl_decoded_option and the other not etc., this is harder, plus
> >the missing and non-int cases are IMHO short enough that it is not worth
> >trying hard to avoid the duplication.
> >For the enum case which is larger, it is maybe worth adding
> >a helper routine for it, which would need probably only
> >location_t loc, const struct cl_enum *e, const char *opt, unsigned int lang_mask
> >arguments.  Can try that on Monday.
> 
> Maybe you can split the error printing code out of read_cmdline_option. For
> the original patch I noticed the duplication but figured it was not enough
> to really worry about, but for the error handling I think we should make an
> effort.

So like this?

2015-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR c/48088
	PR c/68657
	* common.opt (Wframe-larger-than=): Add Warning.
	* opts.h (control_warning_option): Add ARG argument.
	* opts-common.c (cmdline_handle_error): New function.
	(read_cmdline_option): Use it.
	(control_warning_option): Likewise.  Add ARG argument.
	If non-NULL, decode it if needed and pass through
	to handle_generated_option.  Handle CLVC_ENUM like
	CLVC_BOOLEAN.
	* opts.c (common_handle_option): Adjust control_warning_option
	caller.
	(enable_warning_as_error): Likewise.
c-family/
	* c.opt (Wfloat-conversion, Wsign-conversion): Add Warning.
	* c-pragma.c (handle_pragma_diagnostic): Adjust
	control_warning_option caller.
ada/
	* gcc-interface/trans.c (Pragma_to_gnu): Adjust
	control_warning_option caller.
testsuite/
	* c-c++-common/pr68657-1.c: New test.
	* c-c++-common/pr68657-2.c: New test.
	* c-c++-common/pr68657-3.c: New test.

--- gcc/common.opt.jj	2015-12-06 12:20:38.496706114 +0100
+++ gcc/common.opt	2015-12-07 13:56:34.167539666 +0100
@@ -581,7 +581,7 @@ Common Var(flag_fatal_errors)
 Exit on the first error occurred.
 
 Wframe-larger-than=
-Common RejectNegative Joined UInteger
+Common RejectNegative Joined UInteger Warning
 -Wframe-larger-than=<number>	Warn if a function's stack frame requires more than <number> bytes.
 
 Wfree-nonheap-object
--- gcc/opts.h.jj	2015-12-04 18:55:34.150960576 +0100
+++ gcc/opts.h	2015-12-07 13:56:34.189539357 +0100
@@ -363,7 +363,7 @@ extern void read_cmdline_option (struct
 				 const struct cl_option_handlers *handlers,
 				 diagnostic_context *dc);
 extern void control_warning_option (unsigned int opt_index, int kind,
-				    bool imply, location_t loc,
+				    const char *arg, bool imply, location_t loc,
 				    unsigned int lang_mask,
 				    const struct cl_option_handlers *handlers,
 				    struct gcc_options *opts,
--- gcc/opts-common.c.jj	2015-12-04 18:55:34.097961330 +0100
+++ gcc/opts-common.c	2015-12-07 14:34:01.714160852 +0100
@@ -1021,62 +1021,38 @@ generate_option_input_file (const char *
   decoded->errors = 0;
 }
 
-/* Handle the switch DECODED (location LOC) for the language indicated
-   by LANG_MASK, using the handlers in *HANDLERS and setting fields in
-   OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
-   diagnostic options.  */
+/* Perform diagnostics for read_cmdline_option and control_warning_option
+   functions.  Returns true if an error has been diagnosed.  */
 
-void
-read_cmdline_option (struct gcc_options *opts,
-		     struct gcc_options *opts_set,
-		     struct cl_decoded_option *decoded,
-		     location_t loc,
-		     unsigned int lang_mask,
-		     const struct cl_option_handlers *handlers,
-		     diagnostic_context *dc)
+static bool
+cmdline_handle_error (location_t loc, const struct cl_option *option,
+		      const char *opt, const char *arg, int errors,
+		      unsigned int lang_mask)
 {
-  const struct cl_option *option;
-  const char *opt = decoded->orig_option_with_args_text;
-
-  if (decoded->warn_message)
-    warning_at (loc, 0, decoded->warn_message, opt);
-
-  if (decoded->opt_index == OPT_SPECIAL_unknown)
-    {
-      if (handlers->unknown_option_callback (decoded))
-	error_at (loc, "unrecognized command line option %qs", decoded->arg);
-      return;
-    }
-
-  if (decoded->opt_index == OPT_SPECIAL_ignore)
-    return;
-
-  option = &cl_options[decoded->opt_index];
-
-  if (decoded->errors & CL_ERR_DISABLED)
+  if (errors & CL_ERR_DISABLED)
     {
       error_at (loc, "command line option %qs"
-		" is not supported by this configuration", opt);
-      return;
+		     " is not supported by this configuration", opt);
+      return true;
     }
 
-  if (decoded->errors & CL_ERR_MISSING_ARG)
+  if (errors & CL_ERR_MISSING_ARG)
     {
       if (option->missing_argument_error)
 	error_at (loc, option->missing_argument_error, opt);
       else
 	error_at (loc, "missing argument to %qs", opt);
-      return;
+      return true;
     }
 
-  if (decoded->errors & CL_ERR_UINT_ARG)
+  if (errors & CL_ERR_UINT_ARG)
     {
       error_at (loc, "argument to %qs should be a non-negative integer",
 		option->opt_text);
-      return;
+      return true;
     }
 
-  if (decoded->errors & CL_ERR_ENUM_ARG)
+  if (errors & CL_ERR_ENUM_ARG)
     {
       const struct cl_enum *e = &cl_enums[option->var_enum];
       unsigned int i;
@@ -1084,7 +1060,7 @@ read_cmdline_option (struct gcc_options
       char *s, *p;
 
       if (e->unknown_error)
-	error_at (loc, e->unknown_error, decoded->arg);
+	error_at (loc, e->unknown_error, arg);
       else
 	error_at (loc, "unrecognized argument in option %qs", opt);
 
@@ -1105,9 +1081,49 @@ read_cmdline_option (struct gcc_options
 	}
       p[-1] = 0;
       inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
+      return true;
+    }
+
+  return false;
+}
+
+/* Handle the switch DECODED (location LOC) for the language indicated
+   by LANG_MASK, using the handlers in *HANDLERS and setting fields in
+   OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
+   diagnostic options.  */
+
+void
+read_cmdline_option (struct gcc_options *opts,
+		     struct gcc_options *opts_set,
+		     struct cl_decoded_option *decoded,
+		     location_t loc,
+		     unsigned int lang_mask,
+		     const struct cl_option_handlers *handlers,
+		     diagnostic_context *dc)
+{
+  const struct cl_option *option;
+  const char *opt = decoded->orig_option_with_args_text;
+
+  if (decoded->warn_message)
+    warning_at (loc, 0, decoded->warn_message, opt);
+
+  if (decoded->opt_index == OPT_SPECIAL_unknown)
+    {
+      if (handlers->unknown_option_callback (decoded))
+	error_at (loc, "unrecognized command line option %qs", decoded->arg);
       return;
     }
 
+  if (decoded->opt_index == OPT_SPECIAL_ignore)
+    return;
+
+  option = &cl_options[decoded->opt_index];
+
+  if (decoded->errors
+      && cmdline_handle_error (loc, option, opt, decoded->arg,
+			       decoded->errors, lang_mask))
+    return;
+
   if (decoded->errors & CL_ERR_WRONG_LANG)
     {
       handlers->wrong_lang_callback (decoded, lang_mask);
@@ -1332,8 +1348,8 @@ get_option_state (struct gcc_options *op
    used by -Werror= and #pragma GCC diagnostic.  */
 
 void
-control_warning_option (unsigned int opt_index, int kind, bool imply,
-			location_t loc, unsigned int lang_mask,
+control_warning_option (unsigned int opt_index, int kind, const char *arg,
+			bool imply, location_t loc, unsigned int lang_mask,
 			const struct cl_option_handlers *handlers,
 			struct gcc_options *opts,
 			struct gcc_options *opts_set,
@@ -1347,10 +1363,59 @@ control_warning_option (unsigned int opt
     diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
   if (imply)
     {
+      const struct cl_option *option = &cl_options[opt_index];
+
       /* -Werror=foo implies -Wfoo.  */
-      if (cl_options[opt_index].var_type == CLVC_BOOLEAN)
-	handle_generated_option (opts, opts_set,
-				 opt_index, NULL, 1, lang_mask,
-				 kind, loc, handlers, dc);
+      if (option->var_type == CLVC_BOOLEAN || option->var_type == CLVC_ENUM)
+	{
+	  int value = 1;
+
+	  if (arg && *arg == '\0' && !option->cl_missing_ok)
+	    arg = NULL;
+
+	  if ((option->flags & CL_JOINED) && arg == NULL)
+	    {
+	      cmdline_handle_error (loc, option, option->opt_text, arg,
+				    CL_ERR_MISSING_ARG, lang_mask);
+	      return;
+	    }
+
+	  /* If the switch takes an integer, convert it.  */
+	  if (arg && option->cl_uinteger)
+	    {
+	      value = integral_argument (arg);
+	      if (value == -1)
+		{
+		  cmdline_handle_error (loc, option, option->opt_text, arg,
+					CL_ERR_UINT_ARG, lang_mask);
+		  return;
+		}
+	    }
+
+	  /* If the switch takes an enumerated argument, convert it.  */
+	  if (arg && option->var_type == CLVC_ENUM)
+	    {
+	      const struct cl_enum *e = &cl_enums[option->var_enum];
+
+	      if (enum_arg_to_value (e->values, arg, &value, lang_mask))
+		{
+		  const char *carg = NULL;
+
+		  if (enum_value_to_arg (e->values, &carg, value, lang_mask))
+		    arg = carg;
+		  gcc_assert (carg != NULL);
+		}
+	      else
+		{
+		  cmdline_handle_error (loc, option, option->opt_text, arg,
+					CL_ERR_ENUM_ARG, lang_mask);
+		  return;
+		}
+	    }
+
+	  handle_generated_option (opts, opts_set,
+				   opt_index, arg, value, lang_mask,
+				   kind, loc, handlers, dc);
+	}
     }
 }
--- gcc/opts.c.jj	2015-12-04 18:55:34.144960661 +0100
+++ gcc/opts.c	2015-12-07 13:56:34.190539343 +0100
@@ -2114,7 +2114,7 @@ common_handle_option (struct gcc_options
 
     case OPT_pedantic_errors:
       dc->pedantic_errors = 1;
-      control_warning_option (OPT_Wpedantic, DK_ERROR, value,
+      control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set,
                               dc);
@@ -2437,8 +2437,11 @@ enable_warning_as_error (const char *arg
   else
     {
       const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
+      const char *arg = NULL;
 
-      control_warning_option (option_index, (int) kind, value,
+      if (cl_options[option_index].flags & CL_JOINED)
+	arg = new_option + cl_options[option_index].opt_len;
+      control_warning_option (option_index, (int) kind, arg, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set, dc);
     }
--- gcc/c-family/c.opt.jj	2015-12-04 18:55:34.113961102 +0100
+++ gcc/c-family/c.opt	2015-12-07 13:56:34.211539048 +0100
@@ -435,7 +435,7 @@ C ObjC RejectNegative Warning Alias(Werr
 This switch is deprecated; use -Werror=implicit-function-declaration instead.
 
 Wfloat-conversion
-C ObjC C++ ObjC++ Var(warn_float_conversion) LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
+C ObjC C++ ObjC++ Var(warn_float_conversion) Warning LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
 Warn for implicit type conversions that cause loss of floating point precision.
 
 Wfloat-equal
@@ -837,7 +837,7 @@ C ObjC C++ ObjC++ EnabledBy(Wextra)
 ;
 
 Wsign-conversion
-C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
+C ObjC C++ ObjC++ Var(warn_sign_conversion) Warning LangEnabledBy(C ObjC,Wconversion)
 Warn for implicit type conversions between signed and unsigned integers.
 
 Wsign-promo
--- gcc/c-family/c-pragma.c.jj	2015-12-04 18:55:34.129960875 +0100
+++ gcc/c-family/c-pragma.c	2015-12-07 13:56:34.217538963 +0100
@@ -814,7 +814,11 @@ handle_pragma_diagnostic(cpp_reader *ARG
 
   struct cl_option_handlers handlers;
   set_default_handlers (&handlers);
-  control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
+  const char *arg = NULL;
+  if (cl_options[option_index].flags & CL_JOINED)
+    arg = option_string + 1 + cl_options[option_index].opt_len;
+  control_warning_option (option_index, (int) kind,
+			  arg, kind != DK_IGNORED,
 			  loc, lang_mask, &handlers,
 			  &global_options, &global_options_set,
 			  global_dc);
--- gcc/ada/gcc-interface/trans.c.jj	2015-12-04 18:55:34.090961429 +0100
+++ gcc/ada/gcc-interface/trans.c	2015-12-07 13:56:34.229538795 +0100
@@ -1441,6 +1441,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 
 	/* This is the same implementation as in the C family of compilers.  */
 	const unsigned int lang_mask = CL_Ada | CL_COMMON;
+	const char *arg = NULL;
 	if (Present (gnat_expr))
 	  {
 	    tree gnu_expr = gnat_to_gnu (gnat_expr);
@@ -1464,12 +1465,14 @@ Pragma_to_gnu (Node_Id gnat_node)
 		post_error ("?-W switch not valid for Ada", gnat_node);
 		break;
 	      }
+	    if (cl_options[option_index].flags & CL_JOINED)
+	      arg = option_string + 1 + cl_options[option_index].opt_len;
 	  }
 	else
 	  option_index = 0;
 
 	set_default_handlers (&handlers);
-	control_warning_option (option_index, (int) kind, imply, location,
+	control_warning_option (option_index, (int) kind, arg, imply, location,
 				lang_mask, &handlers, &global_options,
 				&global_options_set, global_dc);
       }
--- gcc/testsuite/c-c++-common/pr68657-1.c.jj	2015-12-07 13:56:34.229538795 +0100
+++ gcc/testsuite/c-c++-common/pr68657-1.c	2015-12-07 13:56:34.229538795 +0100
@@ -0,0 +1,26 @@
+/* PR c/68657 */
+/* { dg-options "-Werror=sign-conversion -Werror=float-conversion -Werror=frame-larger-than=65536" } */
+
+void
+f1 (void)
+{
+  unsigned int a = -5;	/* { dg-error "negative integer implicitly converted to unsigned type" } */
+  (void) a;
+}
+
+int
+f2 (void)
+{
+  return 3.1f;	/* { dg-error "conversion to 'int' alters 'float' constant value" } */
+}
+
+int f3 (char *);
+
+int
+f4 (void)
+{
+  char buf[131072];
+  return f3 (buf);
+}		/* { dg-error "the frame size of 1\[0-9]* bytes is larger than 65536 bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-2.c.jj	2015-12-07 13:56:34.229538795 +0100
+++ gcc/testsuite/c-c++-common/pr68657-2.c	2015-12-07 13:56:34.229538795 +0100
@@ -0,0 +1,8 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=larger-than=65536" } */
+
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-3.c.jj	2015-12-07 13:56:34.230538781 +0100
+++ gcc/testsuite/c-c++-common/pr68657-3.c	2015-12-07 13:56:34.230538781 +0100
@@ -0,0 +1,13 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+
+#pragma GCC diagnostic error "-Wlarger-than=65536"
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic ignored "-Wlarger-than=65536"
+int c[131072];	/* { dg-bogus "size of 'c' is \[1-9]\[0-9]* bytes" } */
+int d[1024];	/* { dg-bogus "size of 'd' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic warning "-Wlarger-than=65536"
+int e[131072];	/* { dg-warning "size of 'e' is \[1-9]\[0-9]* bytes" } */
+int f[1024];	/* { dg-bogus "size of 'f' is \[1-9]\[0-9]* bytes" } */
+/* { dg-prune-output "treated as errors" } */


	Jakub

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-07 13:45           ` Jakub Jelinek
@ 2015-12-07 15:11             ` Bernd Schmidt
  2015-12-07 22:42               ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Bernd Schmidt @ 2015-12-07 15:11 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Manuel López-Ibáñez, Joseph S. Myers, Gcc Patch List

On 12/07/2015 02:44 PM, Jakub Jelinek wrote:
>
> So like this?

> +/* Perform diagnostics for read_cmdline_option and control_warning_option
> +   functions.  Returns true if an error has been diagnosed.  */

Let's document arguments; for the ones identical to read_cmdline_option 
an explicit pointer there is sufficient, but errors is new.

> @@ -1332,8 +1348,8 @@ get_option_state (struct gcc_options *op
>      used by -Werror= and #pragma GCC diagnostic.  */
>
>   void
> -control_warning_option (unsigned int opt_index, int kind, bool imply,
> -			location_t loc, unsigned int lang_mask,
> +control_warning_option (unsigned int opt_index, int kind, const char *arg,
> +			bool imply, location_t loc, unsigned int lang_mask,

This also needs an update to the function comment.

Other than that I'm ok with this. This area could probably be 
restructured a bit but for now I think this is good enough.


Bernd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-07 15:11             ` Bernd Schmidt
@ 2015-12-07 22:42               ` Jakub Jelinek
  2015-12-08 11:56                 ` Bernd Schmidt
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2015-12-07 22:42 UTC (permalink / raw)
  To: Bernd Schmidt
  Cc: Manuel López-Ibáñez, Joseph S. Myers, Gcc Patch List

On Mon, Dec 07, 2015 at 04:11:48PM +0100, Bernd Schmidt wrote:
> Let's document arguments; for the ones identical to read_cmdline_option an
> explicit pointer there is sufficient, but errors is new.

> This also needs an update to the function comment.
> 
> Other than that I'm ok with this. This area could probably be restructured a
> bit but for now I think this is good enough.

So like this?  Bootstrapped/regtested on x86_64-linux and i686-linux.

2015-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR c/48088
	PR c/68657
	* common.opt (Wframe-larger-than=): Add Warning.
	* opts.h (control_warning_option): Add ARG argument.
	* opts-common.c (cmdline_handle_error): New function.
	(read_cmdline_option): Use it.
	(control_warning_option): Likewise.  Add ARG argument.
	If non-NULL, decode it if needed and pass through
	to handle_generated_option.  Handle CLVC_ENUM like
	CLVC_BOOLEAN.
	* opts.c (common_handle_option): Adjust control_warning_option
	caller.
	(enable_warning_as_error): Likewise.
c-family/
	* c.opt (Wfloat-conversion, Wsign-conversion): Add Warning.
	* c-pragma.c (handle_pragma_diagnostic): Adjust
	control_warning_option caller.
ada/
	* gcc-interface/trans.c (Pragma_to_gnu): Adjust
	control_warning_option caller.
testsuite/
	* c-c++-common/pr68657-1.c: New test.
	* c-c++-common/pr68657-2.c: New test.
	* c-c++-common/pr68657-3.c: New test.
	* gcc.dg/cpp/warn-normalized-3.c: Use
	-Werror=normalized=nfc instead of -Werror=normalized=
	in dg-options.

--- gcc/common.opt.jj	2015-12-06 12:20:38.496706114 +0100
+++ gcc/common.opt	2015-12-07 13:56:34.167539666 +0100
@@ -581,7 +581,7 @@ Common Var(flag_fatal_errors)
 Exit on the first error occurred.
 
 Wframe-larger-than=
-Common RejectNegative Joined UInteger
+Common RejectNegative Joined UInteger Warning
 -Wframe-larger-than=<number>	Warn if a function's stack frame requires more than <number> bytes.
 
 Wfree-nonheap-object
--- gcc/opts.h.jj	2015-12-04 18:55:34.150960576 +0100
+++ gcc/opts.h	2015-12-07 13:56:34.189539357 +0100
@@ -363,7 +363,7 @@ extern void read_cmdline_option (struct
 				 const struct cl_option_handlers *handlers,
 				 diagnostic_context *dc);
 extern void control_warning_option (unsigned int opt_index, int kind,
-				    bool imply, location_t loc,
+				    const char *arg, bool imply, location_t loc,
 				    unsigned int lang_mask,
 				    const struct cl_option_handlers *handlers,
 				    struct gcc_options *opts,
--- gcc/opts-common.c.jj	2015-12-04 18:55:34.097961330 +0100
+++ gcc/opts-common.c	2015-12-07 18:44:00.764807029 +0100
@@ -1021,62 +1021,42 @@ generate_option_input_file (const char *
   decoded->errors = 0;
 }
 
-/* Handle the switch DECODED (location LOC) for the language indicated
-   by LANG_MASK, using the handlers in *HANDLERS and setting fields in
-   OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
-   diagnostic options.  */
-
-void
-read_cmdline_option (struct gcc_options *opts,
-		     struct gcc_options *opts_set,
-		     struct cl_decoded_option *decoded,
-		     location_t loc,
-		     unsigned int lang_mask,
-		     const struct cl_option_handlers *handlers,
-		     diagnostic_context *dc)
+/* Perform diagnostics for read_cmdline_option and control_warning_option
+   functions.  Returns true if an error has been diagnosed.
+   LOC and LANG_MASK arguments like in read_cmdline_option.
+   OPTION is the option to report diagnostics for, OPT the name
+   of the option as text, ARG the argument of the option (for joined
+   options), ERRORS is bitmask of CL_ERR_* values.  */
+
+static bool
+cmdline_handle_error (location_t loc, const struct cl_option *option,
+		      const char *opt, const char *arg, int errors,
+		      unsigned int lang_mask)
 {
-  const struct cl_option *option;
-  const char *opt = decoded->orig_option_with_args_text;
-
-  if (decoded->warn_message)
-    warning_at (loc, 0, decoded->warn_message, opt);
-
-  if (decoded->opt_index == OPT_SPECIAL_unknown)
-    {
-      if (handlers->unknown_option_callback (decoded))
-	error_at (loc, "unrecognized command line option %qs", decoded->arg);
-      return;
-    }
-
-  if (decoded->opt_index == OPT_SPECIAL_ignore)
-    return;
-
-  option = &cl_options[decoded->opt_index];
-
-  if (decoded->errors & CL_ERR_DISABLED)
+  if (errors & CL_ERR_DISABLED)
     {
       error_at (loc, "command line option %qs"
-		" is not supported by this configuration", opt);
-      return;
+		     " is not supported by this configuration", opt);
+      return true;
     }
 
-  if (decoded->errors & CL_ERR_MISSING_ARG)
+  if (errors & CL_ERR_MISSING_ARG)
     {
       if (option->missing_argument_error)
 	error_at (loc, option->missing_argument_error, opt);
       else
 	error_at (loc, "missing argument to %qs", opt);
-      return;
+      return true;
     }
 
-  if (decoded->errors & CL_ERR_UINT_ARG)
+  if (errors & CL_ERR_UINT_ARG)
     {
       error_at (loc, "argument to %qs should be a non-negative integer",
 		option->opt_text);
-      return;
+      return true;
     }
 
-  if (decoded->errors & CL_ERR_ENUM_ARG)
+  if (errors & CL_ERR_ENUM_ARG)
     {
       const struct cl_enum *e = &cl_enums[option->var_enum];
       unsigned int i;
@@ -1084,7 +1064,7 @@ read_cmdline_option (struct gcc_options
       char *s, *p;
 
       if (e->unknown_error)
-	error_at (loc, e->unknown_error, decoded->arg);
+	error_at (loc, e->unknown_error, arg);
       else
 	error_at (loc, "unrecognized argument in option %qs", opt);
 
@@ -1105,9 +1085,49 @@ read_cmdline_option (struct gcc_options
 	}
       p[-1] = 0;
       inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
+      return true;
+    }
+
+  return false;
+}
+
+/* Handle the switch DECODED (location LOC) for the language indicated
+   by LANG_MASK, using the handlers in *HANDLERS and setting fields in
+   OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for
+   diagnostic options.  */
+
+void
+read_cmdline_option (struct gcc_options *opts,
+		     struct gcc_options *opts_set,
+		     struct cl_decoded_option *decoded,
+		     location_t loc,
+		     unsigned int lang_mask,
+		     const struct cl_option_handlers *handlers,
+		     diagnostic_context *dc)
+{
+  const struct cl_option *option;
+  const char *opt = decoded->orig_option_with_args_text;
+
+  if (decoded->warn_message)
+    warning_at (loc, 0, decoded->warn_message, opt);
+
+  if (decoded->opt_index == OPT_SPECIAL_unknown)
+    {
+      if (handlers->unknown_option_callback (decoded))
+	error_at (loc, "unrecognized command line option %qs", decoded->arg);
       return;
     }
 
+  if (decoded->opt_index == OPT_SPECIAL_ignore)
+    return;
+
+  option = &cl_options[decoded->opt_index];
+
+  if (decoded->errors
+      && cmdline_handle_error (loc, option, opt, decoded->arg,
+			       decoded->errors, lang_mask))
+    return;
+
   if (decoded->errors & CL_ERR_WRONG_LANG)
     {
       handlers->wrong_lang_callback (decoded, lang_mask);
@@ -1327,13 +1347,14 @@ get_option_state (struct gcc_options *op
 /* Set a warning option OPT_INDEX (language mask LANG_MASK, option
    handlers HANDLERS) to have diagnostic kind KIND for option
    structures OPTS and OPTS_SET and diagnostic context DC (possibly
-   NULL), at location LOC (UNKNOWN_LOCATION for -Werror=).  If IMPLY,
+   NULL), at location LOC (UNKNOWN_LOCATION for -Werror=).  ARG is the
+   argument of the option for joined options, or NULL otherwise.  If IMPLY,
    the warning option in question is implied at this point.  This is
    used by -Werror= and #pragma GCC diagnostic.  */
 
 void
-control_warning_option (unsigned int opt_index, int kind, bool imply,
-			location_t loc, unsigned int lang_mask,
+control_warning_option (unsigned int opt_index, int kind, const char *arg,
+			bool imply, location_t loc, unsigned int lang_mask,
 			const struct cl_option_handlers *handlers,
 			struct gcc_options *opts,
 			struct gcc_options *opts_set,
@@ -1347,10 +1368,59 @@ control_warning_option (unsigned int opt
     diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
   if (imply)
     {
+      const struct cl_option *option = &cl_options[opt_index];
+
       /* -Werror=foo implies -Wfoo.  */
-      if (cl_options[opt_index].var_type == CLVC_BOOLEAN)
-	handle_generated_option (opts, opts_set,
-				 opt_index, NULL, 1, lang_mask,
-				 kind, loc, handlers, dc);
+      if (option->var_type == CLVC_BOOLEAN || option->var_type == CLVC_ENUM)
+	{
+	  int value = 1;
+
+	  if (arg && *arg == '\0' && !option->cl_missing_ok)
+	    arg = NULL;
+
+	  if ((option->flags & CL_JOINED) && arg == NULL)
+	    {
+	      cmdline_handle_error (loc, option, option->opt_text, arg,
+				    CL_ERR_MISSING_ARG, lang_mask);
+	      return;
+	    }
+
+	  /* If the switch takes an integer, convert it.  */
+	  if (arg && option->cl_uinteger)
+	    {
+	      value = integral_argument (arg);
+	      if (value == -1)
+		{
+		  cmdline_handle_error (loc, option, option->opt_text, arg,
+					CL_ERR_UINT_ARG, lang_mask);
+		  return;
+		}
+	    }
+
+	  /* If the switch takes an enumerated argument, convert it.  */
+	  if (arg && option->var_type == CLVC_ENUM)
+	    {
+	      const struct cl_enum *e = &cl_enums[option->var_enum];
+
+	      if (enum_arg_to_value (e->values, arg, &value, lang_mask))
+		{
+		  const char *carg = NULL;
+
+		  if (enum_value_to_arg (e->values, &carg, value, lang_mask))
+		    arg = carg;
+		  gcc_assert (carg != NULL);
+		}
+	      else
+		{
+		  cmdline_handle_error (loc, option, option->opt_text, arg,
+					CL_ERR_ENUM_ARG, lang_mask);
+		  return;
+		}
+	    }
+
+	  handle_generated_option (opts, opts_set,
+				   opt_index, arg, value, lang_mask,
+				   kind, loc, handlers, dc);
+	}
     }
 }
--- gcc/opts.c.jj	2015-12-04 18:55:34.144960661 +0100
+++ gcc/opts.c	2015-12-07 13:56:34.190539343 +0100
@@ -2114,7 +2114,7 @@ common_handle_option (struct gcc_options
 
     case OPT_pedantic_errors:
       dc->pedantic_errors = 1;
-      control_warning_option (OPT_Wpedantic, DK_ERROR, value,
+      control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set,
                               dc);
@@ -2437,8 +2437,11 @@ enable_warning_as_error (const char *arg
   else
     {
       const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
+      const char *arg = NULL;
 
-      control_warning_option (option_index, (int) kind, value,
+      if (cl_options[option_index].flags & CL_JOINED)
+	arg = new_option + cl_options[option_index].opt_len;
+      control_warning_option (option_index, (int) kind, arg, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set, dc);
     }
--- gcc/c-family/c.opt.jj	2015-12-04 18:55:34.113961102 +0100
+++ gcc/c-family/c.opt	2015-12-07 13:56:34.211539048 +0100
@@ -435,7 +435,7 @@ C ObjC RejectNegative Warning Alias(Werr
 This switch is deprecated; use -Werror=implicit-function-declaration instead.
 
 Wfloat-conversion
-C ObjC C++ ObjC++ Var(warn_float_conversion) LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
+C ObjC C++ ObjC++ Var(warn_float_conversion) Warning LangEnabledBy(C ObjC C++ ObjC++,Wconversion)
 Warn for implicit type conversions that cause loss of floating point precision.
 
 Wfloat-equal
@@ -837,7 +837,7 @@ C ObjC C++ ObjC++ EnabledBy(Wextra)
 ;
 
 Wsign-conversion
-C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
+C ObjC C++ ObjC++ Var(warn_sign_conversion) Warning LangEnabledBy(C ObjC,Wconversion)
 Warn for implicit type conversions between signed and unsigned integers.
 
 Wsign-promo
--- gcc/c-family/c-pragma.c.jj	2015-12-04 18:55:34.129960875 +0100
+++ gcc/c-family/c-pragma.c	2015-12-07 13:56:34.217538963 +0100
@@ -814,7 +814,11 @@ handle_pragma_diagnostic(cpp_reader *ARG
 
   struct cl_option_handlers handlers;
   set_default_handlers (&handlers);
-  control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
+  const char *arg = NULL;
+  if (cl_options[option_index].flags & CL_JOINED)
+    arg = option_string + 1 + cl_options[option_index].opt_len;
+  control_warning_option (option_index, (int) kind,
+			  arg, kind != DK_IGNORED,
 			  loc, lang_mask, &handlers,
 			  &global_options, &global_options_set,
 			  global_dc);
--- gcc/ada/gcc-interface/trans.c.jj	2015-12-04 18:55:34.090961429 +0100
+++ gcc/ada/gcc-interface/trans.c	2015-12-07 13:56:34.229538795 +0100
@@ -1441,6 +1441,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 
 	/* This is the same implementation as in the C family of compilers.  */
 	const unsigned int lang_mask = CL_Ada | CL_COMMON;
+	const char *arg = NULL;
 	if (Present (gnat_expr))
 	  {
 	    tree gnu_expr = gnat_to_gnu (gnat_expr);
@@ -1464,12 +1465,14 @@ Pragma_to_gnu (Node_Id gnat_node)
 		post_error ("?-W switch not valid for Ada", gnat_node);
 		break;
 	      }
+	    if (cl_options[option_index].flags & CL_JOINED)
+	      arg = option_string + 1 + cl_options[option_index].opt_len;
 	  }
 	else
 	  option_index = 0;
 
 	set_default_handlers (&handlers);
-	control_warning_option (option_index, (int) kind, imply, location,
+	control_warning_option (option_index, (int) kind, arg, imply, location,
 				lang_mask, &handlers, &global_options,
 				&global_options_set, global_dc);
       }
--- gcc/testsuite/c-c++-common/pr68657-1.c.jj	2015-12-07 13:56:34.229538795 +0100
+++ gcc/testsuite/c-c++-common/pr68657-1.c	2015-12-07 13:56:34.229538795 +0100
@@ -0,0 +1,26 @@
+/* PR c/68657 */
+/* { dg-options "-Werror=sign-conversion -Werror=float-conversion -Werror=frame-larger-than=65536" } */
+
+void
+f1 (void)
+{
+  unsigned int a = -5;	/* { dg-error "negative integer implicitly converted to unsigned type" } */
+  (void) a;
+}
+
+int
+f2 (void)
+{
+  return 3.1f;	/* { dg-error "conversion to 'int' alters 'float' constant value" } */
+}
+
+int f3 (char *);
+
+int
+f4 (void)
+{
+  char buf[131072];
+  return f3 (buf);
+}		/* { dg-error "the frame size of 1\[0-9]* bytes is larger than 65536 bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-2.c.jj	2015-12-07 13:56:34.229538795 +0100
+++ gcc/testsuite/c-c++-common/pr68657-2.c	2015-12-07 13:56:34.229538795 +0100
@@ -0,0 +1,8 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=larger-than=65536" } */
+
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68657-3.c.jj	2015-12-07 13:56:34.230538781 +0100
+++ gcc/testsuite/c-c++-common/pr68657-3.c	2015-12-07 13:56:34.230538781 +0100
@@ -0,0 +1,13 @@
+/* PR c/68657 */
+/* { dg-do compile } */
+
+#pragma GCC diagnostic error "-Wlarger-than=65536"
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic ignored "-Wlarger-than=65536"
+int c[131072];	/* { dg-bogus "size of 'c' is \[1-9]\[0-9]* bytes" } */
+int d[1024];	/* { dg-bogus "size of 'd' is \[1-9]\[0-9]* bytes" } */
+#pragma GCC diagnostic warning "-Wlarger-than=65536"
+int e[131072];	/* { dg-warning "size of 'e' is \[1-9]\[0-9]* bytes" } */
+int f[1024];	/* { dg-bogus "size of 'f' is \[1-9]\[0-9]* bytes" } */
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c.jj	2014-11-11 00:06:04.000000000 +0100
+++ gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c	2015-12-07 22:02:20.815256540 +0100
@@ -1,4 +1,4 @@
 // { dg-do preprocess }
-// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=normalized=" }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=normalized=nfc" }
 /* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
 \u0F43  // { dg-error "`.U00000f43' is not in NFC .-Werror=normalized=." }


	Jakub

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657)
  2015-12-07 22:42               ` Jakub Jelinek
@ 2015-12-08 11:56                 ` Bernd Schmidt
  2015-12-11 20:18                   ` [PATCH] Fix -Werror= handling with aliases (PR c/68833) Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Bernd Schmidt @ 2015-12-08 11:56 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Manuel López-Ibáñez, Joseph S. Myers, Gcc Patch List

On 12/07/2015 11:41 PM, Jakub Jelinek wrote:
> On Mon, Dec 07, 2015 at 04:11:48PM +0100, Bernd Schmidt wrote:
>> Let's document arguments; for the ones identical to read_cmdline_option an
>> explicit pointer there is sufficient, but errors is new.
>
>> This also needs an update to the function comment.
>>
>> Other than that I'm ok with this. This area could probably be restructured a
>> bit but for now I think this is good enough.
>
> So like this?  Bootstrapped/regtested on x86_64-linux and i686-linux.

Yes, thanks.


Bernd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] Fix -Werror= handling with aliases (PR c/68833)
  2015-12-08 11:56                 ` Bernd Schmidt
@ 2015-12-11 20:18                   ` Jakub Jelinek
  2015-12-14 16:22                     ` Bernd Schmidt
  0 siblings, 1 reply; 12+ messages in thread
From: Jakub Jelinek @ 2015-12-11 20:18 UTC (permalink / raw)
  To: Bernd Schmidt, Manuel López-Ibáñez, Joseph S. Myers
  Cc: gcc-patches

Hi!

On Tue, Dec 08, 2015 at 12:56:20PM +0100, Bernd Schmidt wrote:
> On 12/07/2015 11:41 PM, Jakub Jelinek wrote:
> >On Mon, Dec 07, 2015 at 04:11:48PM +0100, Bernd Schmidt wrote:
> >>Let's document arguments; for the ones identical to read_cmdline_option an
> >>explicit pointer there is sufficient, but errors is new.
> >
> >>This also needs an update to the function comment.
> >>
> >>Other than that I'm ok with this. This area could probably be restructured a
> >>bit but for now I think this is good enough.
> >
> >So like this?  Bootstrapped/regtested on x86_64-linux and i686-linux.
> 
> Yes, thanks.

Unfortunately, my patch broke some cases with warning aliases that happened
to work (by accident) and left some other warning alias cases broken.

This patch attempts to fix that (and add Warning keyword to two warning
aliases that didn't have it), so that -Werror= works even for them again.
As we do nothing beyond cancelling -Werror for -Wno-error=, there is no need
to deal with neg_alias_arg, just alias_arg is enough.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2015-12-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/68833
	* common.opt (Wmissing-noreturn): Add Warning option.
	* opts-common.c (control_warning_option): If opt is
	alias_target with alias_arg, set arg to it.

	* c.opt (Wmissing-format-attribute, Wnormalized): Add Warning option.

	* c-c++-common/pr68833-1.c: New test.
	* c-c++-common/pr68833-2.c: New test.

--- gcc/common.opt.jj	2015-12-08 14:25:19.000000000 +0100
+++ gcc/common.opt	2015-12-11 16:29:30.257521500 +0100
@@ -612,7 +612,7 @@ Common Var(warn_unsafe_loop_optimization
 Warn if the loop cannot be optimized due to nontrivial assumptions.
 
 Wmissing-noreturn
-Common Alias(Wsuggest-attribute=noreturn)
+Common Warning Alias(Wsuggest-attribute=noreturn)
 
 Wodr
 Common Var(warn_odr_violations) Init(1) Warning
--- gcc/opts-common.c.jj	2015-12-08 14:25:19.000000000 +0100
+++ gcc/opts-common.c	2015-12-11 16:11:16.499755495 +0100
@@ -1361,7 +1361,13 @@ control_warning_option (unsigned int opt
 			diagnostic_context *dc)
 {
   if (cl_options[opt_index].alias_target != N_OPTS)
-    opt_index = cl_options[opt_index].alias_target;
+    {
+      gcc_assert (!cl_options[opt_index].cl_separate_alias
+		  && !cl_options[opt_index].cl_negative_alias);
+      if (cl_options[opt_index].alias_arg)
+	arg = cl_options[opt_index].alias_arg;
+      opt_index = cl_options[opt_index].alias_target;
+    }
   if (opt_index == OPT_SPECIAL_ignore)
     return;
   if (dc)
--- gcc/c-family/c.opt.jj	2015-12-11 09:24:38.000000000 +0100
+++ gcc/c-family/c.opt	2015-12-11 16:30:40.150547817 +0100
@@ -627,7 +627,7 @@ C++ ObjC++ Var(warn_templates) Warning
 Warn on primary template declaration.
 
 Wmissing-format-attribute
-C ObjC C++ ObjC++ Alias(Wsuggest-attribute=format)
+C ObjC C++ ObjC++ Warning Alias(Wsuggest-attribute=format)
 ;
 
 Wmissing-include-dirs
@@ -678,7 +678,7 @@ C ObjC C++ ObjC++ LangEnabledBy(C ObjC C
 ;
 
 Wnormalized
-C ObjC C++ ObjC++ Alias(Wnormalized=,nfc,none)
+C ObjC C++ ObjC++ Warning Alias(Wnormalized=,nfc,none)
 ;
 
 Wnormalized=
--- gcc/testsuite/c-c++-common/pr68833-1.c.jj	2015-12-11 16:15:14.053446857 +0100
+++ gcc/testsuite/c-c++-common/pr68833-1.c	2015-12-11 16:33:41.593020133 +0100
@@ -0,0 +1,22 @@
+/* PR c/68833 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=larger-than-65536 -Werror=format -Werror=missing-noreturn" } */
+
+int a[131072];	/* { dg-error "size of 'a' is \[1-9]\[0-9]* bytes" } */
+int b[1024];	/* { dg-bogus "size of 'b' is \[1-9]\[0-9]* bytes" } */
+
+void
+f1 (const char *fmt)
+{
+  __builtin_printf ("%d\n", 1.2);	/* { dg-error "expects argument of type" } */
+  __builtin_printf (fmt, 1.2);		/* { dg-bogus "format not a string literal, argument types not checked" } */
+}
+
+extern void f2 (void);
+void
+f2 (void) /* { dg-error "candidate for attribute 'noreturn'" "detect noreturn candidate" } */
+{
+  __builtin_exit (0);
+}
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68833-2.c.jj	2015-12-11 16:27:32.571160818 +0100
+++ gcc/testsuite/c-c++-common/pr68833-2.c	2015-12-11 16:28:15.296565741 +0100
@@ -0,0 +1,16 @@
+/* PR c/68833 */
+/* { dg-do compile } */
+/* { dg-options "-Werror=missing-format-attribute" } */
+
+#include <stdarg.h>
+
+void
+foo (const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  __builtin_vprintf (fmt, ap); /* { dg-error "candidate" "printf attribute warning" } */
+  va_end (ap);
+}
+
+/* { dg-prune-output "treated as errors" } */
--- gcc/testsuite/c-c++-common/pr68833-3.c.jj	2015-12-11 16:38:53.803670711 +0100
+++ gcc/testsuite/c-c++-common/pr68833-3.c	2015-12-11 16:41:28.699512849 +0100
@@ -0,0 +1,7 @@
+/* PR c/68833 */
+/* { dg-do preprocess } */
+/* { dg-options "-Werror=normalized" } */
+
+\u0F43  // { dg-error "`.U00000f43' is not in NFC .-Werror=normalized=." }
+
+/* { dg-prune-output "treated as errors" } */


	Jakub

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Fix -Werror= handling with aliases (PR c/68833)
  2015-12-11 20:18                   ` [PATCH] Fix -Werror= handling with aliases (PR c/68833) Jakub Jelinek
@ 2015-12-14 16:22                     ` Bernd Schmidt
  0 siblings, 0 replies; 12+ messages in thread
From: Bernd Schmidt @ 2015-12-14 16:22 UTC (permalink / raw)
  To: Jakub Jelinek, Manuel López-Ibáñez, Joseph S. Myers
  Cc: gcc-patches

On 12/11/2015 09:18 PM, Jakub Jelinek wrote:
>
> Unfortunately, my patch broke some cases with warning aliases that happened
> to work (by accident) and left some other warning alias cases broken.
>
> This patch attempts to fix that (and add Warning keyword to two warning
> aliases that didn't have it), so that -Werror= works even for them again.
> As we do nothing beyond cancelling -Werror for -Wno-error=, there is no need
> to deal with neg_alias_arg, just alias_arg is enough.

Took me a while to figure out what you were saying with that last 
sentence, but in the end I agree.

> 2015-12-11  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR c/68833
> 	* common.opt (Wmissing-noreturn): Add Warning option.
> 	* opts-common.c (control_warning_option): If opt is
> 	alias_target with alias_arg, set arg to it.
>
> 	* c.opt (Wmissing-format-attribute, Wnormalized): Add Warning option.
>
> 	* c-c++-common/pr68833-1.c: New test.
> 	* c-c++-common/pr68833-2.c: New test.

Ok.


Bernd

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-12-14 16:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 16:37 [PATCH] Fix -Werror= handling for Joined warnings, add a few missing Warning keywords (PRs c/48088, c/68657) Jakub Jelinek
2015-12-04 17:02 ` Bernd Schmidt
2015-12-04 17:53   ` Jakub Jelinek
2015-12-04 18:20     ` Manuel López-Ibáñez
2015-12-04 19:37       ` Jakub Jelinek
2015-12-07 10:24         ` Bernd Schmidt
2015-12-07 13:45           ` Jakub Jelinek
2015-12-07 15:11             ` Bernd Schmidt
2015-12-07 22:42               ` Jakub Jelinek
2015-12-08 11:56                 ` Bernd Schmidt
2015-12-11 20:18                   ` [PATCH] Fix -Werror= handling with aliases (PR c/68833) Jakub Jelinek
2015-12-14 16:22                     ` Bernd Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).