From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 96DE93858D37; Wed, 5 Oct 2022 17:33:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96DE93858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664991236; bh=7rVkMAKfshjR4GsfoFYZirgV22rOAtJ2EPSG+dTWolI=; h=From:To:Subject:Date:From; b=LKfQujZba/p8fprtPJTlqyiVanmzk71wahB6wgXRjA/OkDseCnU8l+24I6FLemOwy 6nT/fYg0DaorIiVhz2JhIErwZXJclBArs4XDoQdAVOiyXlFjrgZgW7hdwtPqXC9Tzs 89HQSsHD2MHBYxXgZvvtHnsmX3tuI6/+Z+RGEymI= From: "vanyacpp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107161] New: gcc doesn't constant fold member if any other member is mutable Date: Wed, 05 Oct 2022 17:33:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vanyacpp at gmail dot com 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=3D107161 Bug ID: 107161 Summary: gcc doesn't constant fold member if any other member is mutable Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vanyacpp at gmail dot com Target Milestone: --- On this code: struct mytype { int a; mutable int b; }; extern mytype const p =3D {1, 2}; int foo() { return p.a + 10; } int bar() { return p.b + 10; } GCC -O2 generates: foo(): mov eax, DWORD PTR p[rip] add eax, 10 ret bar(): mov eax, DWORD PTR p[rip+4] add eax, 10 ret While clang folds "p.a + 10" into 11: foo(): # @foo() mov eax, 11 ret bar(): # @bar() mov eax, dword ptr [rip + p+4] add eax, 10 ret I think GCC should do the same.=