public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102919] New: spurious -Wrestrict warning for sprintf into the same member array as argument plus offset
@ 2021-10-24 22:12 msebor at gcc dot gnu.org
2021-10-24 22:12 ` [Bug tree-optimization/102919] " msebor at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-24 22:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102919
Bug ID: 102919
Summary: spurious -Wrestrict warning for sprintf into the same
member array as argument plus offset
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The write below by sprintf into p->a cannot overlap with the read from p->a + 2
because the length of the string at p->a + 2 is at most 1. The only it might
overlap is if the string was longer than fits in the array which would make the
sprintf call invalid for another reason: reading past the end. The -Wrestrict
instance should be avoided here.
$ cat z.c && gcc -O2 -S -Wall z.c
struct A { char a[4]; int i; };
void f (struct A *p)
{
__builtin_sprintf (p->a, "%s", p->a + 2);
}
z.c: In function ‘void f(A*)’:
z.c:5:21: warning: ‘__builtin_sprintf’ argument 3 may overlap destination
object ‘p’ [-Wrestrict]
5 | __builtin_sprintf (p->a, "%s", p->a + 2);
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
z.c:3:19: note: destination object referenced by ‘restrict’-qualified argument
1 was declared here
3 | void f (struct A *p)
| ~~~~~~~~~~^
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/102919] spurious -Wrestrict warning for sprintf into the same member array as argument plus offset
2021-10-24 22:12 [Bug tree-optimization/102919] New: spurious -Wrestrict warning for sprintf into the same member array as argument plus offset msebor at gcc dot gnu.org
@ 2021-10-24 22:12 ` msebor at gcc dot gnu.org
2021-10-24 23:44 ` msebor at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-24 22:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102919
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Blocks| |84774
Last reconfirmed| |2021-10-24
Keywords| |diagnostic
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84774
[Bug 84774] [meta-bug] bogus/missing -Wrestrict
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/102919] spurious -Wrestrict warning for sprintf into the same member array as argument plus offset
2021-10-24 22:12 [Bug tree-optimization/102919] New: spurious -Wrestrict warning for sprintf into the same member array as argument plus offset msebor at gcc dot gnu.org
2021-10-24 22:12 ` [Bug tree-optimization/102919] " msebor at gcc dot gnu.org
@ 2021-10-24 23:44 ` msebor at gcc dot gnu.org
2021-10-26 22:54 ` cvs-commit at gcc dot gnu.org
2021-10-26 23:03 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-24 23:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102919
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
Target Milestone|--- |12.0
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582446.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/102919] spurious -Wrestrict warning for sprintf into the same member array as argument plus offset
2021-10-24 22:12 [Bug tree-optimization/102919] New: spurious -Wrestrict warning for sprintf into the same member array as argument plus offset msebor at gcc dot gnu.org
2021-10-24 22:12 ` [Bug tree-optimization/102919] " msebor at gcc dot gnu.org
2021-10-24 23:44 ` msebor at gcc dot gnu.org
@ 2021-10-26 22:54 ` cvs-commit at gcc dot gnu.org
2021-10-26 23:03 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-26 22:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102919
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:1ff4dbddcf74203a1e16316b18e12f9e1b5085f0
commit r12-4727-g1ff4dbddcf74203a1e16316b18e12f9e1b5085f0
Author: Martin Sebor <msebor@redhat.com>
Date: Tue Oct 26 14:40:33 2021 -0600
Improve/correct detection of overlapping aggregates [PR102238, PR102919].
Resolves:
PR tree-optimization/102238 - alias_offset in gimple-ssa-sprintf.c is
broken
PR tree-optimization/102919 - spurious -Wrestrict warning for sprintf into
the same member array as argument plus offset
gcc/ChangeLog:
PR tree-optimization/102238
PR tree-optimization/102919
* gimple-ssa-sprintf.c (get_string_length): Add an argument.
(array_elt_at_offset): Move to pointer-query.
(set_aggregate_size_and_offset): New function.
(field_at_offset): Move to pointer-query.
(get_origin_and_offset): Rename...
(get_origin_and_offset_r): this. Add an argument. Make aggregate
handling more robust.
(get_origin_and_offset): New.
(alias_offset): Add an argument.
(format_string): Use subobject size determined by
get_origin_and_offset.
* pointer-query.cc (field_at_offset): Move from
gimple-ssa-sprintf.c.
Improve/correct handling of aggregates.
(array_elt_at_offset): Same.
* pointer-query.h (field_at_offset): Declare.
(array_elt_at_offset): Declare.
gcc/testsuite/ChangeLog:
PR tree-optimization/102238
PR tree-optimization/102919
* gcc.dg/tree-ssa/builtin-sprintf-warn-23.c: Remove warnings.
* gcc.dg/Wrestrict-23.c: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/102919] spurious -Wrestrict warning for sprintf into the same member array as argument plus offset
2021-10-24 22:12 [Bug tree-optimization/102919] New: spurious -Wrestrict warning for sprintf into the same member array as argument plus offset msebor at gcc dot gnu.org
` (2 preceding siblings ...)
2021-10-26 22:54 ` cvs-commit at gcc dot gnu.org
@ 2021-10-26 23:03 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-26 23:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102919
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Done r12-4727.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-10-26 23:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 22:12 [Bug tree-optimization/102919] New: spurious -Wrestrict warning for sprintf into the same member array as argument plus offset msebor at gcc dot gnu.org
2021-10-24 22:12 ` [Bug tree-optimization/102919] " msebor at gcc dot gnu.org
2021-10-24 23:44 ` msebor at gcc dot gnu.org
2021-10-26 22:54 ` cvs-commit at gcc dot gnu.org
2021-10-26 23:03 ` msebor at gcc dot gnu.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).