From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 077383858CD1; Mon, 8 Apr 2024 18:56:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 077383858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712602575; bh=7BbXoViZBPBd/RU8MFwxAFM/ayakDRiePdhDAfgK+Cc=; h=From:To:Subject:Date:From; b=xcwQE9/CPQqehfPP/8kSHsrjH3+dpjCo2MCTni5gXA8+VS6pgzu68MYwmF737C91I eEkenmjULsE4rF835LAKOZFRQIq4BIDmifF4MscD+Z9T6SeacWQpHhyZi2bPDfKuWq mHKZB0znVNjGB4wnlOK7e1DSRjDSTDdVraIT9Oic= From: "zsojka at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114644] New: wrong -Wrestrict on snprintf() of distinct struct array members Date: Mon, 08 Apr 2024 18:56:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: zsojka at seznam dot cz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone cf_gcchost cf_gcctarget attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114644 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=3D57905&action=3Dedit testcase Output: $ gcc-14 -Wall res.c -c res.c: In function =E2=80=98f2=E2=80=99: res.c:4:25: warning: =E2=80=98__builtin_snprintf=E2=80=99 argument 4 overla= ps destination object =E2=80=98s=E2=80=99 [-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 =E2=80=98restrict=E2=80= =99-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 i= s 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' mig= ht 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=