From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0FF9B385EC57; Mon, 16 Nov 2020 12:16:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FF9B385EC57 From: "alex at sunopti dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug d/97843] Bad code gen when concatenating to array Date: Mon, 16 Nov 2020 12:16:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: d X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alex at sunopti dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ibuclaw at gdcproject dot 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 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, 16 Nov 2020 12:16:18 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97843 --- Comment #2 from Alex --- I agree that the order of evaluation of operands is undefined and writing c= ode that depends on that order would not be reliable. In this case it's the execution of the assign expression happening before all the operands have b= een evaluated that is the problem. The arithmetic equivalent would be for: X +=3D 4/2 To be produce: Immediate load Register with 4 Add register with 4 in it to x Divide register with 4 in it by 2 Resulting in x being increased by 4 instead of 2 10.2.3 Binary expressions EXCEPT for AssignExpression are left to right 10.2.7 says operand order is undefined Nowhere does the spec say that the assignment operator has to happen after operand evaluation. I think this is a hole in the spec.=