This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C PATCH to reject va_arg (ap, void) (PR c/65901)


On Wed, Apr 29, 2015 at 06:41:22PM +0200, Marek Polacek wrote:
> On Tue, Apr 28, 2015 at 09:07:09PM -0600, Martin Sebor wrote:
> > The error message in the test cases below isn't quite right.
> > The type of the aggregates isn't undefined, it's incomplete.
> > Looking at the function, I wonder if the first argument
> > should be EXPR rather than than NULL_TREE? Alternatively,
> > experimenting with other cases where GCC diagnoses invalid
> > uses of incomplete type, I see that it issues:
> > 
> >   "invalid application of %qs to incomplete type %qT"
> > 
> > which might work even better here since we could name the
> > expression (va_arg).
> 
> Yeah, I haven't concerned myself with the exact wording of the error
> message much, and I agree it could be improved.  But passing down the
> EXPR would mean that the compiler outputs "'ap' has an incomplete type"
> and that looks wrong as well.  I think I'm going to apply the following
> tomorrow if I hear no objections (and it passes testing).  Thanks for noticing.

Committed now.
 
> (And I think c_incomplete_type_error deserves some TLC; I'll post a separate
> patch.)
> 
> 2015-04-29  Marek Polacek  <polacek@redhat.com>
> 
> 	* c-typeck.c (c_build_va_arg): Clarify the error message.
> 
> 	* gcc.dg/pr65901.c (foo): Adjust dg-error.
> 
> diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
> index c58e918..028d2f81 100644
> --- gcc/c/c-typeck.c
> +++ gcc/c/c-typeck.c
> @@ -12645,14 +12645,17 @@ c_build_qualified_type (tree type, int type_quals)
>  tree
>  c_build_va_arg (location_t loc, tree expr, tree type)
>  {
> -  if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
> -    warning_at (loc, OPT_Wc___compat,
> -		"C++ requires promoted type, not enum type, in %<va_arg%>");
> -  if (type == error_mark_node || !COMPLETE_TYPE_P (type))
> +  if (error_operand_p (type))
> +    return error_mark_node;
> +  else if (!COMPLETE_TYPE_P (type))
>      {
> -      c_incomplete_type_error (NULL_TREE, type);
> +      error_at (loc, "second argument to %<va_arg%> is of incomplete "
> +		"type %qT", type);
>        return error_mark_node;
>      }
> +  else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
> +    warning_at (loc, OPT_Wc___compat,
> +		"C++ requires promoted type, not enum type, in %<va_arg%>");
>    return build_va_arg (loc, expr, type);
>  }
>  
> diff --git gcc/testsuite/gcc.dg/pr65901.c gcc/testsuite/gcc.dg/pr65901.c
> index 8708a1e..b40eea3 100644
> --- gcc/testsuite/gcc.dg/pr65901.c
> +++ gcc/testsuite/gcc.dg/pr65901.c
> @@ -9,8 +9,8 @@ union U;
>  void
>  foo (__builtin_va_list ap)
>  {
> -  __builtin_va_arg (ap, void);  /* { dg-error "invalid use of void expression" } */
> -  __builtin_va_arg (ap, struct S);  /* { dg-error "invalid use of undefined type" } */
> -  __builtin_va_arg (ap, enum E);  /* { dg-error "invalid use of undefined type" } */
> -  __builtin_va_arg (ap, union U);  /* { dg-error "invalid use of undefined type" } */
> +  __builtin_va_arg (ap, void);  /* { dg-error "second argument to .va_arg. is of incomplete type .void." } */
> +  __builtin_va_arg (ap, struct S);  /* { dg-error "second argument to .va_arg. is of incomplete type .struct S." } */
> +  __builtin_va_arg (ap, enum E);  /* { dg-error "second argument to .va_arg. is of incomplete type .enum E." } */
> +  __builtin_va_arg (ap, union U);  /* { dg-error "second argument to .va_arg. is of incomplete type .union U." } */
>  }

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]