From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EB64D3857C62; Mon, 14 Sep 2020 16:20:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB64D3857C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600100427; bh=Sc/MHZKzXbfxhdAo4EgLOGx0kIZKolvRocL9BX73WWk=; h=From:To:Subject:Date:From; b=LAWyEl91ca/HDeJkP9HHqKeAkKG5tRhWx+1ty3K2zbzllAgFiIk++tzMf+W9qzlor VXViodEXj25FjGVNJmvtlw8LOExgGYRRxB8tTKnpMi4/jzRLApfojik7EnHizQ+FUK eh2xx00inj7HnUimATZnAB75cWSS9cJrI+F/sKTg= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/97047] New: missing warning reading past the end of a constant string returned from a function Date: Mon, 14 Sep 2020 16:20:27 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone 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 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: Mon, 14 Sep 2020 16:20:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97047 Bug ID: 97047 Summary: missing warning reading past the end of a constant string returned from a function Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The first call to memcpy below triggers a warning for reading past the end = of the string returned from f(), but the second call doesn't. $ cat x.c && gcc -O2 -S -Wall -fdump-tree-optimized=3D/dev/stdout x.c const char* f (void) { return "123"; } char a[32]; void g (void) { __builtin_memcpy (a, "123", sizeof a); // warning (good) } void h (void) { __builtin_memcpy (a, f (), sizeof a); // missing warning (bug) } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1931, cgraph_uid=3D1, symbol_o= rder=3D0) f () { [local count: 1073741824]: return "123"; } x.c: In function =E2=80=98g=E2=80=99: x.c:7:3: warning: =E2=80=98__builtin_memcpy=E2=80=99 forming offset [4, 31]= is out of the bounds [0, 4] [-Warray-bounds] 7 | __builtin_memcpy (a, "123", sizeof a); // warning (good) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Function g (g, funcdef_no=3D1, decl_uid=3D1935, cgraph_uid=3D2, symbol_o= rder=3D2) g () { [local count: 1073741824]: __builtin_memcpy (&a, "123", 32); [tail call] return; } ;; Function h (h, funcdef_no=3D2, decl_uid=3D1938, cgraph_uid=3D3, symbol_o= rder=3D3) h () { [local count: 1073741824]: MEM [(char * {ref-all})&a] =3D MEM [(char * {ref-all})"123"]; return; }=