From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F4813858D38; Thu, 21 Mar 2024 20:01:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F4813858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711051276; bh=rwONdpj44KFyWzPYxk1hEfrvqYPdfrgxcMhw9TWNNdQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PXhgoXrlVtY/DDFzsn2VOWmysKn6xvoAKlcDvRr9QENVsa0CxKA/l6duH/CeM0Nm6 93k7ZxSGz3G1j0+0HIFH6/kDwbog37SFDsUhK+3Q4EF/AvCaZn9gkPuKy7sjy1IGCu mIogRrXrD+l4pChMMx9aE0+wFpltUbpvFBQoAEMo= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114421] arm-none-eabi thumb -Os (and -O2) incorrectly optimizes out needed class member call Date: Thu, 21 Mar 2024 20:01:15 +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: 12.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xry111 at gcc dot gnu.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: cc 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=3D114421 Xi Ruoyao changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |xry111 at gcc dot gnu.org --- Comment #3 from Xi Ruoyao --- (In reply to Earle F. Philhower, III from comment #2) > Thanks very much for the fast explanation. For reference of others who > might hit this, I see references to C11 6.8.5 pp 6 online (but of course > it's an ISO document so not freely available). >=20 > "An iteration statement whose controlling expression is not a constant > expression, that performs no input/output operations, does not access > volatile objects, and performs no synchronization or atomic operations in > its body, controlling expression, or (in the case of a for statement) its > expression-3, may be assumed by the implementation to terminate." For this topic C++ is actually more strict than C so referring the C standa= rd may be still misleading. In C++ there is no "the controlling expression is a constant expression" exempt, so even while (true); can be optimized out. AFAIK GCC does not optimize away while (true); in C++, but Clang is actively doing this. Ther= e is a WG21 paper to add the constant expression exemption for C++ like C (I can= not remember its Nxxxx ID though).=