public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Martin Sebor <msebor@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	       Joseph Myers <joseph@codesourcery.com>
Subject: Re: C PATCH to reject va_arg (ap, void) (PR c/65901)
Date: Thu, 30 Apr 2015 14:17:00 -0000	[thread overview]
Message-ID: <20150430133711.GI3384@redhat.com> (raw)
In-Reply-To: <20150429164122.GB3384@redhat.com>

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

      reply	other threads:[~2015-04-30 13:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 17:30 Marek Polacek
2015-04-27 17:56 ` Jeff Law
2015-04-29  3:50 ` Martin Sebor
2015-04-29 16:49   ` Marek Polacek
2015-04-30 14:17     ` Marek Polacek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150430133711.GI3384@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=msebor@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).