[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-20 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

Jeffrey A. Law  changed:

   What|Removed |Added

   Target Milestone|8.0 |9.0

--- Comment #13 from Jeffrey A. Law  ---
I think this needs to defer to gcc-9.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-19 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #12 from H.J. Lu  ---
(In reply to Martin Sebor from comment #11)
> 
> Until then, the only way to avoid the warning that I can think of is to
> exclude from checking arguments passed through the ellipsis, but that will
> result in some false negatives for sprintf et al.  So the question is: do
> the benefits of the warning outweigh the cost of the false positives.
> 

It is a regression that GCC 8 can't compile lib/str_error_r.c in Linux kernel
without modifications.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-19 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

Martin Sebor  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=83688,
   ||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=83859

--- Comment #11 from Martin Sebor  ---
The warning will go away once -Wrestrict is implemented for sprintf, hopefully
in GCC 9 (the patch I submitted in July didn't make it to GCC 8:
https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00036.html), and the handling for
the built-in functions removed from the front-end.  This is being tracked in
bug 83688.

Until then, the only way to avoid the warning that I can think of is to exclude
from checking arguments passed through the ellipsis, but that will result in
some false negatives for sprintf et al.  So the question is: do the benefits of
the warning outweigh the cost of the false positives.

The potential for false positives here also isn't limited to sprintf.  It's a
general problem that affects user-defined functions as well.  For example:

$ cat z.c && gcc -S -Wall z.c
void f (char* restrict, const char* restrict, const void*);

void g (char *s)
{
  f (s, "", s);
}

z.c: In function ‘g’:
z.c:5:3: warning: passing argument 1 to restrict-qualified parameter aliases
with argument 3 [-Wrestrict]
   f (s, "", s);
   ^

The only way to avoid these false positives (and negatives) is to add some
annotation to let users indicate how each argument is used (e.g., such as the
attributes read_only and write_only that I've been working on).  This is being
tracked in bug 83859.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-19 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #10 from H.J. Lu  ---
(In reply to H.J. Lu from comment #9)
> (In reply to Jakub Jelinek from comment #8)
> > Not aware of any right now, but 1) if the format string is not compile time
> > known, we don't know if it is %p or not 2) the format string parsing is done
> 
> We only need to handle the known format string case.
> 
> > in other passes (-Wformat code in FEs, and gimple-ssa-sprintf.c) compared to
> > the restrict warning.
> 
> This shouldn't be the reason not to do it.

If there is no way to fix it, we should warn (char *) cases under -Wextra,
not under -Wall.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-19 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #9 from H.J. Lu  ---
(In reply to Jakub Jelinek from comment #8)
> Not aware of any right now, but 1) if the format string is not compile time
> known, we don't know if it is %p or not 2) the format string parsing is done

We only need to handle the known format string case.

> in other passes (-Wformat code in FEs, and gimple-ssa-sprintf.c) compared to
> the restrict warning.

This shouldn't be the reason not to do it.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-19 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #8 from Jakub Jelinek  ---
Not aware of any right now, but 1) if the format string is not compile time
known, we don't know if it is %p or not 2) the format string parsing is done in
other passes (-Wformat code in FEs, and gimple-ssa-sprintf.c) compared to the
restrict warning.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-19 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

Richard Biener  changed:

   What|Removed |Added

   Keywords||diagnostic
   Target Milestone|--- |8.0

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-17 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #7 from H.J. Lu  ---
(In reply to Jakub Jelinek from comment #6)
> On the other side, the warning matches the documented behavior and it might
> be too difficult to add all the exceptions when we know that the argument
> will not be really dereferenced.

How many exceptions are there, beside %p?

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #6 from Jakub Jelinek  ---
On the other side, the warning matches the documented behavior and it might be
too difficult to add all the exceptions when we know that the argument will not
be really dereferenced.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek  ---
Yeah, only arguments corresponding to %s/%ls/%S/%n or whatever else can
actually dereference the pointer (for *scanf of course all the pointers).

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-16 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

--- Comment #4 from H.J. Lu  ---
(In reply to Jeffrey A. Law from comment #3)
> Umm, isn't that invalid code?  The whole point of the warning is to catch
> precisely this kind of broken idiom.  Right?

Why is it invalid?  Argument 4 is for %p. It looks valid to me.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-16 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

Jeffrey A. Law  changed:

   What|Removed |Added

 CC||law at redhat dot com

--- Comment #3 from Jeffrey A. Law  ---
Umm, isn't that invalid code?  The whole point of the warning is to catch
precisely this kind of broken idiom.  Right?

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-16 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

H.J. Lu  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #2 from H.J. Lu  ---
This is caused by r258455.

[Bug c/84919] [8 Regression] error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]

2018-03-16 Thread hjl.tools at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84919

H.J. Lu  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-03-16
 Ever confirmed|0   |1

--- Comment #1 from H.J. Lu  ---
[hjl@gnu-bdx-1 tmp]$ cat x.c
#include 
#include 
char *str_error_r(char *buf, size_t buflen)
{
snprintf(buf, buflen, "(%p, %zd)", buf, buflen);
return buf;
}
[hjl@gnu-bdx-1 tmp]$ /usr/gcc-8.0.1-x32/bin/gcc -O2 -S -Wall x.c
x.c: In function ‘str_error_r’:
x.c:5:2: warning: passing argument 1 to restrict-qualified parameter aliases
with argument 4 [-Wrestrict]
  snprintf(buf, buflen, "(%p, %zd)", buf, buflen);
  ^~~~
[hjl@gnu-bdx-1 tmp]$