From patchwork Wed Jul 28 11:24:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1510809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=om2OZCqd; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GZWf64DNWz9sRN for ; Wed, 28 Jul 2021 21:29:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 946483992030 for ; Wed, 28 Jul 2021 11:29:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 946483992030 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627471767; bh=anh1lHi21CkgRXke9NjCOba62/Zm2Tyf0SnoAnMH//A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=om2OZCqdKRQijbwUJ6NeXK91AJ8au4h3nLHC52txHA+Ep8BJDQ97XlI+f1/G9RvGa KPzfYBeVfwbY1VK8SSnso1XUWsYF8LsqUM8r4rq+aCopZTx83La9Vbkak1TYmv2ibR ALY9naXNtXW0Lv3XuC9fpXXyDWG8cJCbYE2ngrEc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id 8AE613990C1E for ; Wed, 28 Jul 2021 11:24:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8AE613990C1E Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4GZWXf51Z6zQjh9; Wed, 28 Jul 2021 13:24:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id kSxw7fAU3aNq; Wed, 28 Jul 2021 13:24:43 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Wrong evaluation order of binary expressions (PR101640) Date: Wed, 28 Jul 2021 13:24:42 +0200 Message-Id: <20210728112442.3740448-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 27F9718CA X-Rspamd-UID: b285b7 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, The use of fold_build2 can in some cases swap the order of its operands if that is the more optimal thing to do. However this breaks semantic guarantee of left-to-right evaluation in D. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32. Committed to mainline, and backported to the gcc-9, gcc-10, and gcc-11 release branches. Regards, Iain. --- gcc/d/ChangeLog: PR d/101640 * expr.cc (binary_op): Use build2 instead of fold_build2. gcc/testsuite/ChangeLog: PR d/101640 * gdc.dg/pr96429.d: Update test. * gdc.dg/pr101640.d: New test. --- gcc/d/expr.cc | 2 +- gcc/testsuite/gdc.dg/pr101640.d | 11 +++++++++++ gcc/testsuite/gdc.dg/pr96429.d | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr101640.d diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index e76cae98f7e..b78778eb8ef 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -157,7 +157,7 @@ binary_op (tree_code code, tree type, tree arg0, tree arg1) eptype = type; } - ret = fold_build2 (code, eptype, arg0, arg1); + ret = build2 (code, eptype, arg0, arg1); } return d_convert (type, ret); diff --git a/gcc/testsuite/gdc.dg/pr101640.d b/gcc/testsuite/gdc.dg/pr101640.d new file mode 100644 index 00000000000..68de4088512 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr101640.d @@ -0,0 +1,11 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101640 +// { dg-do compile } +// { dg-options "-fdump-tree-original" } + +int fun101640(ref int); + +int test101640(int val) +{ + // { dg-final { scan-tree-dump "= val \\\+ fun101640 \\\(\\\(int &\\\) &val\\\);" "original" } } + return val + fun101640(val); +} diff --git a/gcc/testsuite/gdc.dg/pr96429.d b/gcc/testsuite/gdc.dg/pr96429.d index af096e26b5a..9940a03e0ec 100644 --- a/gcc/testsuite/gdc.dg/pr96429.d +++ b/gcc/testsuite/gdc.dg/pr96429.d @@ -3,7 +3,7 @@ // { dg-options "-fdump-tree-original" } ptrdiff_t subbyte(byte* bp1, byte* bp2) { - // { dg-final { scan-tree-dump "bp1 - bp2;" "original" } } + // { dg-final { scan-tree-dump "\\\(bp1 - bp2\\\) /\\\[ex\\\] 1;" "original" } } return bp1 - bp2; }