From patchwork Sat Jul 1 14:14:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1802254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.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=c2zK5wuq; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QtZ250pynz20ZV for ; Sun, 2 Jul 2023 00:14:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B0083858D38 for ; Sat, 1 Jul 2023 14:14:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B0083858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688220874; bh=TJpwOE7/g88DYB1EZiLPjY8vkdq2llGSbJjXp84cRRw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=c2zK5wuqfIcJa+gW2CPkid1Hgce4/w8wBDZLLb5rIUiqB4Y1OWk4c4n7EkcCqWugx VZleprHN8v8Ay+bMKS6qINrrOU5LzSXiONQvbTP/ttAC6Jy0qayYisOXAhN+Uf9RkT MyHLaoHAUURPQLq73td2hTzM1ztm336dMbx/15Ag= 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 0B28C3858D35 for ; Sat, 1 Jul 2023 14:14:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B28C3858D35 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4QtZ1b5tbQz9sRM; Sat, 1 Jul 2023 16:14:11 +0200 (CEST) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [GCC 11][committed] d: Fix ICE in setValue, at d/dmd/dinterpret.c:7013 Date: Sat, 1 Jul 2023 16:14:10 +0200 Message-Id: <20230701141410.2891380-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, This patch backports ICE fix from upstream which is already part of GCC-12 and later. When casting null to integer or real, instead of painting the type on the NullExp, we emplace an IntegerExp/RealExp with the value zero. Same as when casting from NullExp to bool. Bootstrapped and regression tested on x86_64-linux-gnu, committed to releases/gcc-11, and backported to releases/gcc-10. Regards, Iain. --- Reviewed-on: https://github.com/dlang/dmd/pull/13172 PR d/110511 gcc/d/ChangeLog: * dmd/dinterpret.c (Interpreter::visit (CastExp *)): Handle casting null to int or float. gcc/testsuite/ChangeLog: * gdc.test/compilable/test21794.d: New test. --- gcc/d/dmd/dinterpret.c | 12 ++++- gcc/testsuite/gdc.test/compilable/test21794.d | 52 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gdc.test/compilable/test21794.d diff --git a/gcc/d/dmd/dinterpret.c b/gcc/d/dmd/dinterpret.c index ab9d88c660c..d4cfb0caacb 100644 --- a/gcc/d/dmd/dinterpret.c +++ b/gcc/d/dmd/dinterpret.c @@ -5792,12 +5792,22 @@ public: } if (e->to->ty == Tsarray) e1 = resolveSlice(e1); - if (e->to->toBasetype()->ty == Tbool && e1->type->ty == Tpointer) + Type *tobt = e->to->toBasetype(); + if (tobt->ty == Tbool && e1->type->ty == Tpointer) { new(pue) IntegerExp(e->loc, e1->op != TOKnull, e->to); result = pue->exp(); return; } + else if (tobt->isTypeBasic() && e1->op == TOKnull) + { + if (tobt->isintegral()) + new(pue) IntegerExp(e->loc, 0, e->to); + else if (tobt->isreal()) + new(pue) RealExp(e->loc, CTFloat::zero, e->to); + result = pue->exp(); + return; + } result = ctfeCast(pue, e->loc, e->type, e->to, e1); } diff --git a/gcc/testsuite/gdc.test/compilable/test21794.d b/gcc/testsuite/gdc.test/compilable/test21794.d new file mode 100644 index 00000000000..68e504bce56 --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/test21794.d @@ -0,0 +1,52 @@ +// https://issues.dlang.org/show_bug.cgi?id=21794 +/* +TEST_OUTPUT: +--- +0 +0u +0L +0LU +0.0F +0.0 +0.0L +--- +*/ + +bool fun(void* p) { + const x = cast(ulong)p; + return 1; +} + +static assert(fun(null)); + +T fun2(T)(void* p) { + const x = cast(T)p; + return x; +} + +// These were an error before, they were returning a NullExp instead of IntegerExp/RealExp + +static assert(fun2!int(null) == 0); +static assert(fun2!uint(null) == 0); +static assert(fun2!long(null) == 0); +static assert(fun2!ulong(null) == 0); +static assert(fun2!float(null) == 0); +static assert(fun2!double(null) == 0); +static assert(fun2!real(null) == 0); + +// These were printing 'null' instead of the corresponding number + +const i = cast(int)null; +const ui = cast(uint)null; +const l = cast(long)null; +const ul = cast(ulong)null; +const f = cast(float)null; +const d = cast(double)null; +const r = cast(real)null; +pragma(msg, i); +pragma(msg, ui); +pragma(msg, l); +pragma(msg, ul); +pragma(msg, f); +pragma(msg, d); +pragma(msg, r);