public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114644] New: wrong -Wrestrict on snprintf() of distinct struct array members
@ 2024-04-08 18:56 zsojka at seznam dot cz
  0 siblings, 0 replies; only message in thread
From: zsojka at seznam dot cz @ 2024-04-08 18:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114644

            Bug ID: 114644
           Summary: wrong -Wrestrict on snprintf() of distinct struct
                    array members
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Created attachment 57905
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57905&action=edit
testcase

Output:
$ gcc-14 -Wall res.c -c
res.c: In function ‘f2’:
res.c:4:25: warning: ‘__builtin_snprintf’ argument 4 overlaps destination
object ‘s’ [-Wrestrict]
    4 | void f2(int i, int j) { __builtin_snprintf(s[i].a, 10, "%s", s[j].b); }
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
res.c:1:31: note: destination object referenced by ‘restrict’-qualified
argument 1 was declared here
    1 | struct { char a[10], b[10]; } s[10];
      |                               ^


as far as I can tell, there should be no warning for snprintf(), as there is no
warning for the other functions. I checked all the PRs in PR84774 and didn't
find any this would be duplication.
Of course I am not a language lawyer, so my understanding of 'restrict' might
be incorrect; but the warning is at least inconsistent:
- only snprintf() warns
- the s[] must be an array
- both i/j indices must be variables
- -Wrestrict alone is not enough to trigger this -Wrestrict warning at -O0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-08 18:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08 18:56 [Bug tree-optimization/114644] New: wrong -Wrestrict on snprintf() of distinct struct array members zsojka at seznam dot cz

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).