{"id":2224791,"url":"http://patchwork.ozlabs.org/api/patches/2224791/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260418171833.457485-1-ibuclaw@gdcproject.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260418171833.457485-1-ibuclaw@gdcproject.org>","list_archive_url":null,"date":"2026-04-18T17:18:33","name":"[committed] d: Fix ICE in gimplify_var_or_parm_decl, at gimplify.cc:3308","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a112c3ece8e4edf0514e677988d9e9671eef00ca","submitter":{"id":46728,"url":"http://patchwork.ozlabs.org/api/people/46728/?format=json","name":"Iain Buclaw","email":"ibuclaw@gdcproject.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260418171833.457485-1-ibuclaw@gdcproject.org/mbox/","series":[{"id":500456,"url":"http://patchwork.ozlabs.org/api/series/500456/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500456","date":"2026-04-18T17:18:33","name":"[committed] d: Fix ICE in gimplify_var_or_parm_decl, at gimplify.cc:3308","version":1,"mbox":"http://patchwork.ozlabs.org/series/500456/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224791/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224791/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gdcproject.org header.i=@gdcproject.org\n header.a=rsa-sha256 header.s=MBO0001 header.b=l8AogdZ7;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=gdcproject.org header.i=@gdcproject.org\n header.a=rsa-sha256 header.s=MBO0001 header.b=l8AogdZ7","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=gdcproject.org","sourceware.org; spf=pass smtp.mailfrom=gdcproject.org","server2.sourceware.org;\n arc=none smtp.remote-ip=80.241.56.151","outgoing_mbo_mout; dkim=none;\n spf=pass (outgoing_mbo_mout: domain of ibuclaw@gdcproject.org designates\n 2001:67c:2050:b231:465::2 as permitted sender)\n smtp.mailfrom=ibuclaw@gdcproject.org"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fydlJ6wLrz1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 19 Apr 2026 03:19:07 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2EA254B920BC\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 17:19:05 +0000 (GMT)","from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151])\n by sourceware.org (Postfix) with ESMTPS id A70884BA2E27\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 17:18:38 +0000 (GMT)","from smtp2.mailbox.org (smtp2.mailbox.org\n [IPv6:2001:67c:2050:b231:465::2])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4fydkh1b37z9tfy;\n Sat, 18 Apr 2026 19:18:36 +0200 (CEST)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 2EA254B920BC","OpenDKIM Filter v2.11.0 sourceware.org A70884BA2E27"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org A70884BA2E27","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org A70884BA2E27","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776532719; cv=none;\n b=HKpm65AJPr1NOzeg1WGcHk8qjqdEF8mF2B672PPmNmqi6MioE0R4I82njgvT6Au2qxeEaJFgViFQh4aIoPiI5ruDtMIhvP5kmuAFduc0hWT5oVs82jJ6yU0A14rBhO3oa3Qv1GU2TmEL4/ownu05PVS/Twu4Z+gtrR1Mk9R4VNY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776532719; c=relaxed/simple;\n bh=3q7olilEKnQaUQdMh8GqoAn9GOifSfCvV1X9I16TRvM=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=siJ8h9X9aKK0Mps5/z+gKwZAHKK+hfGPbjFz0Ws3Bv6OBvP62vRZD4XBzMGzMU4Jx3/y8ajTJIx6780aoBVtl+GOs6GZMYArfizTJv4uLtgn9qNG5mcTzxOTSlvFDEpa5zzQ+r701lfOGx3R63MdmkgXdbPt8jIv0YGIixCZVZY=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gdcproject.org;\n s=MBO0001; t=1776532716;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding;\n bh=pYiCpaybw2wc6P13g6SWhc3dWV1Vp1fWrp8h+HgNKcY=;\n b=l8AogdZ7hmJwBXHhzXTzcqE7GNjs/7blsQiRID43prbOrDLZYKsD4G1pPfT7nmPF1+OCVw\n sHqpvFPd9o9QhoxR3eTQm47ZHOiDKCiWpM7e0oIDgGx0gTV01/4Y2pT4ijtx1ZnF8pL/f6\n PP51kKX3kwmdCxpX9VT2TLdH4uc5onCv7qhB4eKWzl4V0X/jRlpMxAhxvr7GcCT3FMk+cN\n dSXJly+uAPl+s+1cKiF3o/ZcHYhOJIibICmPVaWpibB21uqz7PcUFXPY+C+pWYz4YOlG0k\n fUcAu0d7BqCV/heuo/kbgAJvkeuO71q1sKKOEr5a0AECGNEhrRV9ZBgZ1guhbQ==","From":"Iain Buclaw <ibuclaw@gdcproject.org>","To":"gcc-patches@gcc.gnu.org","Cc":"Iain Buclaw <ibuclaw@gdcproject.org>","Subject":"[committed][PATCH] d: Fix ICE in gimplify_var_or_parm_decl,\n at gimplify.cc:3308","Date":"Sat, 18 Apr 2026 19:18:33 +0200","Message-ID":"<20260418171833.457485-1-ibuclaw@gdcproject.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Rspamd-Queue-Id":"4fydkh1b37z9tfy","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi,\n\nThis patch fixes an ICE during gimplification caused by wrong D code.\n\nThe result type of the assert() should always be the same as its\ninferred expression type, which could either be `void' or `noreturn'.\n\nAlso moves the pattern of calling to BUILT_IN_TRAP to its own codegen\nfunction, as it is repeated quite enough throughout the front-end.\n\nBootstrapped and regtested on x86_64-linux-gnu/-m32.\n\nCommitted to mainline.\n\nRegards,\nIain.\n\n---\n\tPR d/124922\n\ngcc/d/ChangeLog:\n\n\t* d-codegen.cc (build_trap_call): New function.\n\t(build_array_bounds_call): Use it.\n\t(build_bounds_index_condition): Likewise.\n\t(build_bounds_slice_condition): Likewise.\n\t(d_build_call): Likewise.\n\t* expr.cc (ExprVisitor::visit (HaltExp *)): Likewise.\n\t(ExprVisitor::visit (AssertExp *)): Likewise.  Return zero instead of\n\tvoid_node when assert contracts are disabled.\n\t* d-tree.h (build_trap_call): New prototype.\n\ngcc/testsuite/ChangeLog:\n\n\t* gdc.dg/pr124922.d: New test.\n---\n gcc/d/d-codegen.cc              | 21 +++++++++++++++------\n gcc/d/d-tree.h                  |  1 +\n gcc/d/expr.cc                   |  8 +++-----\n gcc/testsuite/gdc.dg/pr124922.d | 11 +++++++++++\n 4 files changed, 30 insertions(+), 11 deletions(-)\n create mode 100644 gcc/testsuite/gdc.dg/pr124922.d","diff":"diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc\nindex 6e397decea0..4303bfcd476 100644\n--- a/gcc/d/d-codegen.cc\n+++ b/gcc/d/d-codegen.cc\n@@ -2007,7 +2007,7 @@ build_array_bounds_call (const Loc &loc)\n {\n   /* Terminate the program with a trap if no D runtime present.  */\n   if (checkaction_trap_p ())\n-    return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);\n+    return build_trap_call ();\n   else\n     {\n       return build_libcall (LIBCALL_ARRAYBOUNDSP, 2,\n@@ -2036,7 +2036,7 @@ build_bounds_index_condition (IndexExp *ie, tree index, tree length)\n   tree boundserr;\n \n   if (checkaction_trap_p ())\n-    boundserr = build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);\n+    boundserr = build_trap_call ();\n   else\n     {\n       boundserr = build_libcall (LIBCALL_ARRAYBOUNDS_INDEXP, 4,\n@@ -2082,10 +2082,7 @@ build_bounds_slice_condition (SliceExp *se, tree lower, tree upper, tree length)\n \t  tree boundserr;\n \n \t  if (checkaction_trap_p ())\n-\t    {\n-\t      boundserr =\n-\t\tbuild_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);\n-\t    }\n+\t    boundserr = build_trap_call ();\n \t  else\n \t    {\n \t      boundserr = build_libcall (LIBCALL_ARRAYBOUNDS_SLICEP, 5,\n@@ -2156,6 +2153,14 @@ checkaction_trap_p (void)\n     }\n }\n \n+/* Build a call to built-in trap().  */\n+\n+tree\n+build_trap_call ()\n+{\n+  return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);\n+}\n+\n /* Returns the TypeFunction class for Type T.\n    Assumes T is already the main variant type (toBasetype).  */\n \n@@ -2397,6 +2402,10 @@ d_build_call (TypeFunction *tf, tree callable, tree object,\n \t    break;\n \t}\n \n+      /* Trap after evaluating all call arguments, as it is not expected that\n+\t we get to this point after the `noreturn' parameter.  */\n+      saved_args = compound_expr (saved_args, build_trap_call ());\n+\n       /* Add a stub result type for the expression.  */\n       tree result = build_zero_cst (TREE_TYPE (ctype));\n       return compound_expr (saved_args, result);\ndiff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h\nindex e6949f37ff2..905eab9239f 100644\n--- a/gcc/d/d-tree.h\n+++ b/gcc/d/d-tree.h\n@@ -608,6 +608,7 @@ extern tree build_bounds_index_condition (IndexExp *, tree, tree);\n extern tree build_bounds_slice_condition (SliceExp *, tree, tree, tree);\n extern bool array_bounds_check (void);\n extern bool checkaction_trap_p (void);\n+extern tree build_trap_call (void);\n extern TypeFunction *get_function_type (Type *);\n extern bool call_side_effect_free_p (FuncDeclaration *, Type *);\n extern bool call_by_alias_p (FuncDeclaration *, FuncDeclaration *);\ndiff --git a/gcc/d/expr.cc b/gcc/d/expr.cc\nindex 5ce1f510dca..e3a97d546e4 100644\n--- a/gcc/d/expr.cc\n+++ b/gcc/d/expr.cc\n@@ -1783,13 +1783,12 @@ public:\n     else if (global.params.useAssert == CHECKENABLEon && checkaction_trap_p ())\n       {\n \t/* Generate: __builtin_trap()  */\n-\ttree fn = builtin_decl_explicit (BUILT_IN_TRAP);\n-\tassert_fail = build_call_expr (fn, 0);\n+\tassert_fail = build_trap_call ();\n       }\n     else\n       {\n \t/* Assert contracts are turned off.  */\n-\tthis->result_ = void_node;\n+\tthis->result_ = build_zero_cst (build_ctype (e->type));\n \treturn;\n       }\n \n@@ -1905,8 +1904,7 @@ public:\n   void visit (HaltExp *) final override\n   {\n     /* Should we use trap() or abort()?  */\n-    tree ttrap = builtin_decl_explicit (BUILT_IN_TRAP);\n-    this->result_ = build_call_expr (ttrap, 0);\n+    this->result_ = build_trap_call ();\n   }\n \n   /* Build a symbol pointer offset expression.  */\ndiff --git a/gcc/testsuite/gdc.dg/pr124922.d b/gcc/testsuite/gdc.dg/pr124922.d\nnew file mode 100644\nindex 00000000000..4a52f682f7f\n--- /dev/null\n+++ b/gcc/testsuite/gdc.dg/pr124922.d\n@@ -0,0 +1,11 @@\n+// { dg-do compile }\n+// { dg-additional-options \"-fno-assert -fdump-tree-original\" }\n+module object;\n+alias noreturn = typeof(*null);\n+void main()\n+{\n+    void function(noreturn) fun;\n+    noreturn bar;\n+    fun(bar);\n+}\n+// { dg-final { scan-tree-dump-times \"__builtin_trap\" 1 \"original\" } }\n","prefixes":["committed"]}