public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dodji Seketeli <dodji@redhat.com>
To: Gabriel Dos Reis <gdr@integrable-solutions.net>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Tom Tromey <tromey@redhat.com>,
	       Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH 11/13] Fix va_start related location
Date: Fri, 27 Apr 2012 15:06:00 -0000	[thread overview]
Message-ID: <m31un9fc47.fsf@redhat.com> (raw)
In-Reply-To: <CAAiZkiAiQrm5f8tpP=ALxqFvzaD1ToJR9uZUYhXF-XbbVVzNmQ@mail.gmail.com>	(Gabriel Dos Reis's message of "Wed, 25 Apr 2012 10:23:18 -0500")

Gabriel Dos Reis <gdr@integrable-solutions.net> writes:

> On Wed, Apr 25, 2012 at 10:20 AM, Dodji Seketeli <dodji@redhat.com> wrote:
>> Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
>>
>>> On Wed, Apr 25, 2012 at 9:04 AM, Dodji Seketeli <dodji@redhat.com> wrote:
>>>> In gcc/testsuite/gcc.dg/pr30457.c, the first warning was not being
>>>> emitted because the relevant location was inside the var_start macro
>>>> defined in a system header.  It can even point to a token for a
>>>> builtin macro there.  This patch unwinds to the first token in real
>>>> source code in that case.
>>>
>>> While you are at it, could you also use a non-zero value for the second
>>> argument argument to warning_at?
>>
>> I couldn't find any obvious value for it.  I am thinking maybe it would
>> make sense to introduction a new -Wva_start to warn about possible
>> dangerous uses of the va_start macro and use that as the second argument
>> for the relevant warnings emitted by fold_builtin_next_arg.  What do you
>> think?
>
> or -Wvarargs?

OK, I have cooked up a patch for this that I will send in a separate
thread shortly.

>>
>> In any case, this topic seems logically unrelated to the purpose of
>> enable -ftrack-macro-expansion by default, so IMHO it would be better to
>> do this in a separate self contain patch.  Among other things, this
>> would ease possible future back-ports.  Would you agree?
>
> OK.

While testing the separate patch, I realized that this one was missing
adjusting the location in another spot.  So I have updated this patch
accordingly.  The patch that adds -Wvarargs will come on top of it, and
will add some needed regression tests for the whole.

Tested on x86_64-unknown-linux-gnu against trunk.  Bootstrap is still
running ...

	* builtins.c (fold_builtin_next_arg): Unwinds to the first
	location in real source code.
---
 gcc/builtins.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index b47f218..5ddc47b 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -12095,6 +12095,13 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
   tree fntype = TREE_TYPE (current_function_decl);
   int nargs = call_expr_nargs (exp);
   tree arg;
+  /* There is good chance the current input_location points inside the
+     definition of the va_start macro (perhaps on the token for
+     builtin) in a system header, so warnings will not be emitted.
+     Use the location in real source code.  */
+  source_location current_location =
+    linemap_unwind_to_first_non_reserved_loc (line_table, input_location,
+					      NULL);
 
   if (!stdarg_p (fntype))
     {
@@ -12119,7 +12126,9 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
 	{
 	  /* Evidently an out of date version of <stdarg.h>; can't validate
 	     va_start's second argument, but can still work as intended.  */
-	  warning (0, "%<__builtin_next_arg%> called without an argument");
+	  warning_at (current_location,
+		      0,
+		      "%<__builtin_next_arg%> called without an argument");
 	  return true;
 	}
       else if (nargs > 1)
@@ -12154,7 +12163,9 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
 	     argument.  We just warn and set the arg to be the last
 	     argument so that we will get wrong-code because of
 	     it.  */
-	  warning (0, "second parameter of %<va_start%> not last named argument");
+	  warning_at (current_location,
+		      0,
+		      "second parameter of %<va_start%> not last named argument");
 	}
 
       /* Undefined by C99 7.15.1.4p4 (va_start):
@@ -12164,8 +12175,12 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
          the default argument promotions, the behavior is undefined."
       */
       else if (DECL_REGISTER (arg))
-        warning (0, "undefined behaviour when second parameter of "
-                 "%<va_start%> is declared with %<register%> storage");
+	{
+	  warning_at (current_location,
+		      0,
+		      "undefined behaviour when second parameter of "
+		      "%<va_start%> is declared with %<register%> storage");
+	}
 
       /* We want to verify the second parameter just once before the tree
 	 optimizers are run and then avoid keeping it in the tree,
-- 
		Dodji

  reply	other threads:[~2012-04-27 15:06 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-10 14:53 Patches to enable -ftrack-macro-expansion by default Dodji Seketeli
2012-04-10 14:55 ` [PATCH 01/11] Fix cpp_sys_macro_p with -ftrack-macro-expansion Dodji Seketeli
2012-04-11 13:40   ` Jason Merrill
2012-04-14 18:05     ` Dodji Seketeli
2012-04-15  3:52       ` Jason Merrill
2012-04-10 14:57 ` [PATCH 02/11] Fix token pasting " Dodji Seketeli
2012-04-11 13:41   ` Jason Merrill
2012-04-14 18:07     ` Dodji Seketeli
2012-04-10 15:08 ` [PATCH 03/11] Fix PCH crash on GTYed pointer-to-scalar field of a Dodji Seketeli
2012-04-11  3:15   ` Laurynas Biveinis
2012-04-10 19:43 ` [PATCH 04/11] Fix expansion point loc for macro-like tokens Dodji Seketeli
2012-04-11 13:46   ` Jason Merrill
2012-04-25  9:07     ` Dodji Seketeli
2012-04-29  4:08       ` Jason Merrill
2012-04-29 16:55         ` Dodji Seketeli
2012-04-30  3:20           ` Jason Merrill
2012-04-10 19:50 ` [PATCH 05/11] Make expand_location resolve to locus in main source file Dodji Seketeli
2012-04-11 13:49   ` Jason Merrill
2012-04-25  9:50     ` Dodji Seketeli
2012-04-25 15:31       ` Dodji Seketeli
2012-04-29  4:11         ` Jason Merrill
2012-04-29 16:57           ` Dodji Seketeli
2012-04-10 19:56 ` [PATCH 06/11] Strip "<built-in>" loc from displayed expansion context Dodji Seketeli
2012-04-11 13:50   ` Jason Merrill
2012-04-10 20:31 ` [PATCH 07/11] Fix -Wuninitialized for -ftrack-macro-expansion Dodji Seketeli
2012-04-11 13:52   ` Jason Merrill
2012-04-11  9:00 ` [PATCH 09/11] Fix va_arg type location Dodji Seketeli
2012-04-11 13:36   ` Gabriel Dos Reis
2012-04-11  9:26 ` [PATCH 08/11] Make conversion warnings work on NULL with -ftrack-macro-expansion Dodji Seketeli
2012-04-11 13:33   ` Gabriel Dos Reis
2012-04-25 13:42     ` Dodji Seketeli
2012-04-25 14:07       ` Gabriel Dos Reis
2012-04-25 14:50         ` Dodji Seketeli
2012-04-25 15:22           ` Gabriel Dos Reis
2012-04-25 13:55 ` [PATCH 10/13] Fix location for static class members Dodji Seketeli
2012-04-25 14:13   ` Gabriel Dos Reis
2012-04-25 14:04 ` [PATCH 11/13] Fix va_start related location Dodji Seketeli
2012-04-25 14:11   ` Gabriel Dos Reis
2012-04-25 15:20     ` Dodji Seketeli
2012-04-25 15:23       ` Gabriel Dos Reis
2012-04-27 15:06         ` Dodji Seketeli [this message]
2012-04-27 21:46           ` Dodji Seketeli
2012-04-28 23:30             ` Gabriel Dos Reis
2012-04-25 14:17 ` [PATCH 12/13] Adjust relevant test cases wrt -ftrack-macro-expansion=[0|2] Dodji Seketeli
2012-04-25 15:25   ` Gabriel Dos Reis
2012-04-29 17:38     ` Dodji Seketeli
2012-04-30  6:23       ` Dodji Seketeli
2012-04-30  7:34         ` Gabriel Dos Reis
2012-04-30 16:09       ` Mike Stump
2012-05-02 17:22         ` Greta Yorsh
2012-04-25 23:23   ` Benjamin Kosnik
2012-04-25 14:33 ` [PATCH 13/13] Switch -ftrack-macro-expansion=2 on by default Dodji Seketeli
2012-04-25 15:27   ` Gabriel Dos Reis
2012-04-25 17:50     ` Tom Tromey
2012-04-30 11:47 ` Patches to enable -ftrack-macro-expansion " Dodji Seketeli
2012-05-08 10:31   ` Andreas Krebbel
2012-08-26  0:28   ` Gerald Pfeifer
2012-08-26  0:41     ` Gabriel Dos Reis
2012-08-26  8:32       ` Dodji Seketeli
2012-08-26 20:01         ` Gerald Pfeifer
2012-08-26 20:14           ` Gabriel Dos Reis

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=m31un9fc47.fsf@redhat.com \
    --to=dodji@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdr@integrable-solutions.net \
    --cc=jason@redhat.com \
    --cc=tromey@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).