public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/112833] New: Missing warnings on restrict misuse
@ 2023-12-03 16:53 alx at kernel dot org
2023-12-03 17:04 ` [Bug c/112833] " alx at kernel dot org
0 siblings, 1 reply; 2+ messages in thread
From: alx at kernel dot org @ 2023-12-03 16:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112833
Bug ID: 112833
Summary: Missing warnings on restrict misuse
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: alx at kernel dot org
Target Milestone: ---
Reproducer:
$ cat restrict.c
long bogus_strtol(const char *restrict s, char **restrict ep, int base);
int
main(void)
{
char buf[3] = "foo";
char *p = buf;
bogus_strtol(p, &p, -42);
}
long
bogus_strtol(const char *restrict s, char **restrict ep, int base)
{
**ep = *s;
return base;
}
$ gcc -Wall -Wextra restrict.c -fanalyzer
$ gcc -Wall -Wextra restrict.c -fanalyzer -O3
I'd expect two -Wrestrict warnings, one at call site, and another at `**ep =
*s;`.
BTW, of course, I'd also expect a warning at calls to strtol(3), which I
consider has a wrong use of restrict in the prototype.
Original report at gcc-help@:
<https://inbox.sourceware.org/gcc-help/ZWyw72QNLhzG874z@debian/T/#t>
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/112833] Missing warnings on restrict misuse
2023-12-03 16:53 [Bug c/112833] New: Missing warnings on restrict misuse alx at kernel dot org
@ 2023-12-03 17:04 ` alx at kernel dot org
0 siblings, 0 replies; 2+ messages in thread
From: alx at kernel dot org @ 2023-12-03 17:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112833
--- Comment #1 from Alejandro Colomar <alx at kernel dot org> ---
Oops, in the reproducer from above, I should only expect a warning at call
site. The definition is correct, since all parameters are restrict, so it's
free to copy one to the other.
Here's a reproducer where the call is fine, but the definition is wrong, and
the compiler doesn't realize:
$ cat restrict.c
#include <string.h>
long bogus2_strtol(const char *s, char **restrict ep, int base);
int
main(void)
{
char buf[3] = "foo";
char *p = buf;
bogus2_strtol(p, &p, -42);
}
long
bogus2_strtol(const char *s, char **restrict ep, int base)
{
memcpy(*ep, s, 1);
return base;
}
$ gcc -Wall -Wextra restrict.c -fanalyzer
$ gcc -Wall -Wextra restrict.c -fanalyzer -O3
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-03 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-03 16:53 [Bug c/112833] New: Missing warnings on restrict misuse alx at kernel dot org
2023-12-03 17:04 ` [Bug c/112833] " alx at kernel dot org
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).