From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8A1873857012; Fri, 9 Oct 2020 12:08:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A1873857012 From: "franke at computer dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/97336] False positive -Wstring-compare warning for strncmp() Date: Fri, 09 Oct 2020 12:08:10 +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: 10.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: franke at computer dot org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Oct 2020 12:08:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97336 --- Comment #2 from Christian Franke --- Sorry, but I disagree that this report is INVALID. Unlike for example -Wstringop-overflow, warnings like -Wstring-compare shou= ld IMO only occur if the warning condition holds for *all* function calls generated by loop unrolling. BTW, if the partial loop unrolling is done manually, the warning should occ= ur, but does not: int f(const char * p, int n) { char buf[10] =3D {0, }; int i =3D 0; if (n <=3D 0) { if (!__builtin_strncmp(buf, "12345", 5) // <=3D=3D no warning && (i =3D=3D 5 || buf[5] =3D=3D ' ')) // <=3D=3D warning if removed return 1; } else { do { buf[i] =3D p[i]; i++; } while (i < (int)sizeof(buf)-1 && i < n); if (!__builtin_strncmp(buf, "12345", 5) && (i =3D=3D 5 || buf[5] =3D=3D ' ')) return 1; } return 0; } With the above code, the warning occurs if the condition "&& (i =3D=3D 5 ||= buf[5] =3D=3D ' ')" is removed. If this is done in the original testcase, the warn= ing does no longer occur.=