From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 440B93858C2C; Mon, 20 Mar 2023 13:08:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 440B93858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679317702; bh=2YwcWbfWRSdW0nhXVE/XpKzG+mAu/+CNtXotbomootM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xuHMseDTEfVwqhGbmTRXwcrGrc8wulj3ZoH2B5kw6MM+PDTFvHmmniuSgPD9hQx3z 5M458GwSiQMGS6bikc/uKp129NNnaBlZUTd/W0UaYfFNzH3xYLYyqTkXgSWJnSuuLN BX0TR74H36Y3WIoBqVbSLRErhvJ23m6DZnJIJtjs= From: "mail+gnu at tzik dot jp" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101361] Bogus -Wstringop-overread warning with -O3 Date: Mon, 20 Mar 2023 13:08:21 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: mail+gnu at tzik dot jp X-Bugzilla-Status: NEW 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=3D101361 --- Comment #13 from Taiju Tsuiki --- I saw a similar inaccurate -Wstringop-overread warning with a smaller reproducer (attached). https://wandbox.org/permlink/EPjH0ZPoA4EWky0e Reproducing gcc was tip of trunk ( https://github.com/gcc-mirror/gcc/commits/33fb1625992ba8180b42988e714460bca= b08ca0f ), and compile options and the error were: $ g++ -Werror -O3 -std=3Dc++20 -c foo.cc In function =E2=80=98auto operator<=3D>(const V&, const V&)=E2=80=99, inlined from =E2=80=98Node* foo(Node*, const V&)=E2=80=99 at minify2/fo= o.cc:33:17: minify2/foo.cc:20:36: error: =E2=80=98int __builtin_memcmp(const void*, con= st void*, long unsigned int)=E2=80=99 specified bound [9223372036854775808, 184467440= 73709551615] exceeds maximum object size 9223372036854775807 (9)=20 [-Werror=3Dstringop-overread] 20 | const auto c =3D __builtin_memcmp(x.beg, y.beg, len) <=3D> 0; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ minify2/foo.cc:17:15: note: source object allocated here 17 | }(x.end - x.beg, y.end - y.beg); | ~~^~~ $ cat foo.cc #include struct Res { long min; std::strong_ordering cmp; }; struct V { const unsigned char* beg =3D nullptr; const unsigned char* end =3D nullptr; }; auto operator<=3D>(const V& x, const V& y) { const auto [len, lencmp] =3D [&](long len_x, long len_y) { auto c =3D len_x <=3D> len_y; return Res{c > 0 ? len_y : len_x, c}; }(x.end - x.beg, y.end - y.beg); if (len) { const auto c =3D __builtin_memcmp(x.beg, y.beg, len) <=3D> 0; if (c !=3D 0) return c; } return lencmp; } struct Node { Node* next =3D nullptr; V v; }; Node* foo(Node* x, const V& k) { while (x && k < x->v) x =3D x->next; return x; }=