From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1B38C3858C41; Tue, 3 Oct 2023 04:34:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B38C3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696307645; bh=bcS0YhW1ii8Y9zIytdFTNw6EHP+FtD1ZCqBr6728ZBk=; h=From:To:Subject:Date:From; b=fdQUBLdV0fVnVQ4L+D6OC6FAN2TGmbx2COb1lf9Ff2VvDUqns81B1KAlnTeUi66/F BxF/pnw1Xwv+jGBth8FYLpDyV4okfhJ6PR/cEkSIcWmoVwEUXlHDVbswlFq45c9XjB v9w+YKOUFNVnacJamB4cBPeDdufhoXOTAcYkRdGs= From: "zfigura at codeweavers dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/111669] New: bogus -Wnonnull in conditionally executed code Date: Tue, 03 Oct 2023 04:34:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: zfigura at codeweavers dot com 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 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=3D111669 Bug ID: 111669 Summary: bogus -Wnonnull in conditionally executed code Product: gcc Version: 13.2.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: zfigura at codeweavers dot com Target Milestone: --- Created attachment 56032 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56032&action=3Dedit reduced testcase, compile with -O2 -Werror=3Dnonnull Sorry about the rather useless title, but I can't really figure out what actually triggers this error. It seems to depend on some arcane combination= of optimizations. I was able to reduce this down to a pretty minimal test case, attached here= . It may be possible to reduce it further but I couldn't easily find a way. The actual code that triggers this is here [1]. lstrcpyA() and lstrcatA() a= re trivial wrappers around strcpy/strcat. The NULL comes from get_search_path(= ) at line 192. The offending strcpy/strcat will never be reached if GetWindowsDirectoryA() returns nonzero, which it always should. However, gcc triggers a -Wnonnull warning anyway. Interestingly, the original Wine code only triggers the warning with -march=3Dbdver2 (or other values of -march), but the reduced testcase trigg= ers it with no -march flags. [1] https://source.winehq.org/git/wine.git/blob/HEAD:/dlls/krnl386.exe16/file.c= #l639=