From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A54A738582B6; Tue, 19 Dec 2023 08:05:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A54A738582B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702973145; bh=+9zZ+RqQ4FsOSJwTyMjRuv8pWU5HArki5u2j1JL1u70=; h=From:To:Subject:Date:From; b=g3cIkLczIEjJKjO24MoGMFrfHOyWLPf7ARI1eGU0q9kSEjLCLdXwxGlCDnrAn0msh bC/IUS5iBGLKrHPuxXfw2kDdENRCqPa6D7+bceRLjA7NITnGbAF6hOijGgqrHRx3nb 6lluuqpyYcqi0hmUJl8Esz2KBGCBbRALVRzTf/Ug= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/113082] New: builtin transforms do not honor errno Date: Tue, 19 Dec 2023 08:05:44 +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.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113082 Bug ID: 113082 Summary: builtin transforms do not honor errno Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- This was split out from PR56888. gcc is changing a program that can rely on errno not being changed to one w= here the C library can change it. (The current C library or any future library = that the resulting binary may be dynamically linked against.) The library is allowed to alter errno when not documented otherwise by 7.5p3 Quoting from the PRs last comment: (In reply to M Welinder from comment #48) > It's your (1). gcc is changing a program that can rely on errno not being > changed to one where the C library can change it. (The current C library= or > any future library that the resulting binary may be dynamically linked > against.) Ick. Standards continue to surprise me ;) > Is there any real-world situation that benefits from introducing these > calls? It has the feel of optimizing for a benchmark. People are good in writing inefficient code and replacing say, an open coded strlen by an actual call to strlen enables followup transforms that rely on strlen appearing as strlen and not an open-coded variant (I realize that technically one might find a way to implement that without actually emitting a call in the end). And yes, optimizing (repeated) calls of strlen or replacing open-coded large memcpy by a library call to optimized functions can make a noticable difference even for non-benchmarks. We're currently generating calls to memcpy, memmove, memset and strlen. We are also replacing memmove with memcpy, printf with puts or putc, all of those transforms are then invalid because of (1) as well. We are treating -fno-math-errno as applying to non-math functions and we don't have any -fno-errno or way of analyzing/annotating whether a program is interested in the state of errno (not only but mainly because identifying accesses to errno is non-trivial).=