From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 958803858CDB; Thu, 5 Oct 2023 05:42:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 958803858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696484578; bh=y5DXQEfBXOByoEjXmaLllVFbp7u0hdZLHgjLrhbWP/k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=r3d2NLZ23kmY6v2NK68oOtCFImHsftrNcFuLn2WzwWJ32KXY3i5LC0ylxbDXANUae 9D23gLN8lpBjO+F8Gh/c7ZsqGTqZ5Eo27NPWLxSMgNx3+01LP5/p1ZNw7JBciDedFk YdbHrE2tu3cIlYZuadWErc5EQJjclX3xTCUrk1qQ= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/111669] bogus -Wnonnull in conditionally executed code Date: Thu, 05 Oct 2023 05:42:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: xry111 at gcc dot gnu.org 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: Message-ID: In-Reply-To: References: 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 --- Comment #4 from Xi Ruoyao --- (In reply to Zeb Figura from comment #3) > (In reply to Xi Ruoyao from comment #2) > > (In reply to Xi Ruoyao from comment #1) > > > The warning given for the reduced test case is correct because it doe= s not > > > make sense. It should be just rewritten as > >=20 > > I mean, the code does not make sense. > >=20 > > And the warning is given exactly because GCC is optimizing the strcpy c= all > > to unreachable. >=20 > If GetWindowsDirectoryA() was idempotent, and GetSystemDirectory16() had = no > other users, that might be true, but as it is I don't think so. >=20 > The pattern both of those functions call is, much like snprintf(), you pa= ss > a buffer and a size, and if the size is 0 then they'll return the size th= at > would have been written if there was a large enough buffer. In that case = the > buffer can be NULL. In trying to reduce the test case down to the minimal > possible complexity I obscured that fact, but regardless I don't think the > reduced testcase is nonsensical. Then that's why -Wnonnull is a warning, not an error. Using -Werror is just telling the compiler "you can reject valid code", any= way.=