From patchwork Wed Jul 8 10:06:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gerris.rs@gmail.com X-Patchwork-Id: 138725 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 869474BA2E16 for ; Wed, 8 Jul 2026 10:07:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 869474BA2E16 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=gc95wBoJ X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id 9D27B4BA23C2 for ; Wed, 8 Jul 2026 10:06:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D27B4BA23C2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9D27B4BA23C2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1033 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783505181; cv=none; b=LGC9h7G8xkJYdIpWzrw0BYkVpCv8yJjAW4tbAiDEkOMh1APXhxRGJhwiw+WEnr+4O3tUy0IsuEiPFp4h9FcoOgpnUvAeSJ0UcxF1bmZvvqkN+esefRsXc+D0AX40gnvW0/PB2Eyun3I8sVu9Ezu8n6fnYgN+92YbmKowL/QdEqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783505181; c=relaxed/simple; bh=SL2pP28xNE1wLIm1Ay6YuYcU3PlSLt+IkkJAKJyB+ZY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=g3wFIagQzw5l5okNADGm5Bvf7rzge1bH5Ha4AaeYrMrdXZxOuankCTSzGLdT1nZAbTKGExhfwcBYCcBilNe14Y2MPRBLZ+CxMFHXnxsrLfkG+G9j6UB+XQ6d8GTB6fRW8ZkTRhxT0X2kwIsG63r+JQSWQEpNX6YnnJIDJLMjqm4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=gc95wBoJ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D27B4BA23C2 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-388b404ea89so623673a91.0 for ; Wed, 08 Jul 2026 03:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783505181; x=1784109981; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fK9ixOYuGX1AhIZ5FF+q7Ew8DDCBcAGdwJAyf1dgyoE=; b=gc95wBoJ/RZxF8gq4dDOnpYezSppU1LgJHTPACNxZTaN6P1mYxZdNHW+YTLQFJhHph 96/I/I74D7LBSJJXPeslNCsb74dUx83jqBxA3S1xqkRk04Dcak6SYcr5NWd7yyHSPmyi oA4X95Prh2yDnNUrAm5lxSnQFmipPl88bJao5/JTeV+XHXN8HuqpxeWGwdy/ctyhgeJH SwGk6yP9Vf+07mXXu2zpR1Qn658cHbAOf1YP3B7KGgmkfGizOJhDGYOAcy64Z921HjVR GLz2NeJNxDMjstYoUenj4BheKji7N5+V/jEZb1j/kF9bZeiE/jy8hWK+vwr4jKGxt48C 5NZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783505181; x=1784109981; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fK9ixOYuGX1AhIZ5FF+q7Ew8DDCBcAGdwJAyf1dgyoE=; b=GMlWEbCNZEcOikXu8nBkJKtN9q+gkA6zLkHe5KOOKKlttxJOkHrBWXtgb3kYBi4MWh ujINz4Ui8Mg/naL66OXUAH7e+x3zjXrd+WNCKMwfmujgD/JWj7ukgRO+ICf56gH8oYAn Ojr+J+BgBp7OK2mNnFEN9ZyORNrN1XOrJ1pZtAQ0/2RUVYLlEADHg/ODh/j1Qm5VFh1y cQXXGNmEwuszDfQXEhNMSLEg7dehgIL6mzD4DEsfBulLaPpjJcb4QIRRf6rAx3hkNLz1 Snf+KtHC7krJWaNNnNvSIz0OcATnUHFEEnXyWbdawIL/p9F5xAQuwJHALhpU/aJ8hUpN YUEQ== X-Gm-Message-State: AOJu0YxpCDsxy0Ff3gWkNXgMfmQtpeubD7kxQXQ7n3LR0C/7Lwp2Ojge KIQykgXf2s5XWzLOtUubAOfgsOiO0c+zcxppqnoNwT0YxDWKrgjGQ3haHt4xwg== X-Gm-Gg: AfdE7cmFWRbQymOTbbn3pH1HJfLinxu2ntOlytH1IzRCa63Bi1KSDMvngQjYWpIbFFg ix7cVxtmmCmTiey8yfJCPNKLgZ62mUH5yaEQ58dH6P9a0QYNkiXfD3kOr0U6zZZXHEOsNMBoQLL wJttD/mjm5OQ4WqAAcX/NHTS/enj2eJ4qZgXKi/wy9My8uzKIvpsY4lqwBndyqHIZMyAqiqfWwC ty4hq/GjWZ8rnvueoyJbXcM2XnB3ZolJAYEvb55HVCUyBHRghcJeg/cC1hmKA3uulBlGaMlZMbE S2hs4tSE2xBGJXldjXWnn3cpCUykAQdOdjTJ0LTt1G/sjbXgtrIUq+vDlhinr3VTLfRwHYGJms3 mZDMM0z643LaK+JWKmWjeiDGGnlBhq+xcNvts9J6RzG1g23L6G0rIc5tNLAgs0L/lw/j2VWjiUY LJSWsJHeoPBrzLiuwz3lgEzN7I94P7kX1iu3btmdLIu8YonNjeK5OjaZRqLWWw8W8C3iAfrMeUG PXh1KkRKIY= X-Received: by 2002:a17:90b:1801:b0:387:d9cc:7dc1 with SMTP id 98e67ed59e1d1-387d9cc8dd9mr6995732a91.19.1783505180600; Wed, 08 Jul 2026 03:06:20 -0700 (PDT) Received: from runnervm5mmn9.3kssg3t0abtefpjlvgkicfjm3d.dx.internal.cloudapp.net ([20.189.179.85]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-311950eb930sm3853100eec.8.2026.07.08.03.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 03:06:19 -0700 (PDT) From: gerris.rs@gmail.com To: gcc-patches@gcc.gnu.org, gcc-rust@gcc.gnu.org Cc: pierre-emmanuel.patry@embecosm.com, arthur.cohen@embecosm.com, dkm+gccrs@kataplop.net, Lishin Subject: [gccrs COMMIT 1/2] gccrs: Emit function-scope drops for unit tail expressions Date: Wed, 8 Jul 2026 10:06:16 +0000 Message-ID: <20260708100618.3141-1-gerris.rs@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Lishin Add the missing drop calls before returning from unit tail expressions. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): Emit current scope drops for unit tail expressions. gcc/testsuite/ChangeLog: * rust/execute/drop-function-scope-unit-tail.rs: New test. Signed-off-by: Lishin --- This change was merged into the gccrs repository and is posted here for upstream visibility and potential drive-by review, as requested by GCC release managers. Each commit email contains a link to its details on github from where you can find the Pull-Request and associated discussions. Commit on github: https://github.com/Rust-GCC/gccrs/commit/1337bc73082ac4fcd5d7e6a2a9c276e12a7a63ac The commit has NOT been mentioned in any issue. The commit has been mentioned in the following pull-request(s): - https://github.com/Rust-GCC/gccrs/pull/4591 gcc/rust/backend/rust-compile-base.cc | 2 + .../execute/drop-function-scope-unit-tail.rs | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/rust/execute/drop-function-scope-unit-tail.rs base-commit: 99edb212c204385d994c72b85e8098be6f464226 diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index e049e18a4..4e618243b 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -739,6 +739,8 @@ HIRCompileBase::compile_function_body (tree fndecl, // just add the stmt expression ctx->add_statement (return_value); + CompileDrop::emit_current_scope_drop_calls (ctx); + // now just return unit expression tree unit_expr = unit_expression (locus); tree return_stmt diff --git a/gcc/testsuite/rust/execute/drop-function-scope-unit-tail.rs b/gcc/testsuite/rust/execute/drop-function-scope-unit-tail.rs new file mode 100644 index 000000000..ab5bf3fb3 --- /dev/null +++ b/gcc/testsuite/rust/execute/drop-function-scope-unit-tail.rs @@ -0,0 +1,46 @@ +// { dg-output "d\r*\nd\r*\n" } +// { dg-additional-options "-w" } +#![feature(no_core)] +#![feature(lang_items)] +#![no_core] + +extern "C" { + fn printf(s: *const i8, ...); +} + +#[lang = "sized"] +pub trait Sized {} + +#[lang = "drop"] +pub trait Drop { + fn drop(&mut self); +} + +struct Droppable; + +impl Drop for Droppable { + fn drop(&mut self) { + let msg = "d\n\0" as *const str as *const i8; + unsafe { + printf(msg); + } + } +} + +fn foo() {} + +fn unit_tail_call() { + let _x = Droppable; + foo() +} + +fn unit_tail_literal() { + let _x = Droppable; + () +} + +fn main() -> i32 { + unit_tail_call(); + unit_tail_literal(); + 0 +} \ No newline at end of file From patchwork Wed Jul 8 10:06:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gerris.rs@gmail.com X-Patchwork-Id: 138724 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1F194BA2E24 for ; Wed, 8 Jul 2026 10:07:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1F194BA2E24 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=ZEVko/rX X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 6B2604BA2E2D for ; Wed, 8 Jul 2026 10:06:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B2604BA2E2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6B2604BA2E2D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783505183; cv=none; b=cNiKEM7p4G8Dqx+MtaYM14SF+N931XVNenqYXonuJpfKSzwGWOVL69DvN7gse4AOw4AsEVmSu6fwazT4BaUkKcnUmj5Fi+K3aDWBrM0F1gQssLI/wxUoDPRKuHNBI83Ha4jyNjmn0nR8A7tUFFFAvFJTfsbQTG0Cnf/+Bq8fIjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783505183; c=relaxed/simple; bh=9+QkKIFAOjK1wCfXleTfh2aWm05IcV5hr199aF4P8WI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=B5S6W2K5On1rl7nbE3vAhO/K4KCE21rX17JgnuV64Amp5aAEOnC9sHhYtEwRtolS6dG6WuMaffN3ta/VnN46Zn7dLHMDe2/B6DxtxC/T2vJ39C79Bw37LSdfYzaPqFj4aHZ56BUBsnyo+a4pDiCzXLRieiTd8RU19pOAt1LpTOI= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=ZEVko/rX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B2604BA2E2D Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-ca00f126b7eso268569a12.2 for ; Wed, 08 Jul 2026 03:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783505182; x=1784109982; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WhE1HOCkGMhnIXKTNqL4dRcXQWxLVFMFlSpyPCnun/c=; b=ZEVko/rXhv1gpv2JPDOYkz7sfwwvCmlZBcq/ym2hWxArvb7QMZAN4d+Tqkc8h9eCDD sAn9V8vUMagbHJLaK0D0no9JNdkUIm9VVmOwVxYsWXvzxbfmoPXcB9vkV0p7roi/uU9n nH4Pgx8zcNVB1XeRIonj5U6sDfLwboI6xNm1jklbmb4qU0dcwBycCs1SMbWfbaj7/kWW yUCiLeIbtvGIj5IbLqy7zBS/cIUYydlNWTACgGPG8pNjTAyI9QbwwlNRf4RVIBRCKWFc 5XzGldoXWVHTPoNyjor7pyOsBHVglS7Hg5HvrmbtklUc6s717Oy3zGlAh7W+nsv5X7nB yW0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783505182; x=1784109982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WhE1HOCkGMhnIXKTNqL4dRcXQWxLVFMFlSpyPCnun/c=; b=YJJ/R9ewlP2YflkuB0tSPC1TqqUqJSf/avxf7cGF0EEEjwEX/weDro9OM24W8LcxaP N2/YwSDwdZ6BX3yH6b7tdcDUl1N00O306WSoLsBtzQ64UNveB4KTWmfsZOx3xRKTp72+ f2dQOyyCLga0bTOGYgoCFavPanK05IQ9KtRN5B2DfKj89e3T8Pwx1Udbs0ag0bf1j6B2 ZXmLFOCjGqSIyt/37MUGWh9Z7mb/PXLYDwdiNYGajxOjL3X7V/PEMmCl7MyDVNE9dScK Sg6yzwLwcKfyErTDGYhqyI6vSl+z1HlIDXssO/xBejdzuaqBWokjps5ks5wNlDCAzS4R Wr/w== X-Gm-Message-State: AOJu0YyvvTe3yZLg+V0lUUXCbAshak0Y9mEe4/ydQTlzh1eIcv5Es2DS +3RmHwwZFhI0dJfdq1ZEbreBQCpuxwpz/hdG/rxdJFrojYZP5n2TM5GhTAGrcQ== X-Gm-Gg: AfdE7cmzfKt34Z0QjR64zSwSha8YDYt9A8a50Ar4FpqJa4Hpb7h8zZbsv34dIoBGpmI JDsxJmjmVh7SxAVdmg+BeCWTK7DLamCXudoePCJ2iFnT3Qb33yczQ8c6Q2Tg0tsjwFy9PYAmNQN tSDIJaWW9//ZD1Yt67em82niTPLtv2k+KjHB6/lPnk9R2eKbQfovDyfFfnqPOqtxrUAneGzoER+ dICMKKyRW+XjRVepdhszBZwnQR7ThewoR9bAdd1b7bypygyCox+tkLdTM0TLaa3+mFRcN4rMFwL T5LNE5u+PTDHObc92bHOx+3wEhmbYMyktw5N0pFfiHGYvR+RNCvn1JC6ZD9Xl4/nBcz7CksGg6u rP+SA07UuwtOil6aM0lVMLKcGSGXU1VYrsCji61Hc11aVzL5v5d8V1DMmt4q0wRhs6bXwOR77A9 GaI7V21/7Wbu/jGhPx/xdRZCz4jd2PXKfaYdRVfH2fVJOBYKA4s580pDWEZEIfB5Ii1O48lOcLw xn7ZAL3Er8= X-Received: by 2002:a05:6a20:6f04:b0:3b7:9c18:c681 with SMTP id adf61e73a8af0-3c0bce21d5bmr2457265637.9.1783505182178; Wed, 08 Jul 2026 03:06:22 -0700 (PDT) Received: from runnervm5mmn9.3kssg3t0abtefpjlvgkicfjm3d.dx.internal.cloudapp.net ([20.189.179.85]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-311950eb930sm3853100eec.8.2026.07.08.03.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 03:06:21 -0700 (PDT) From: gerris.rs@gmail.com To: gcc-patches@gcc.gnu.org, gcc-rust@gcc.gnu.org Cc: pierre-emmanuel.patry@embecosm.com, arthur.cohen@embecosm.com, dkm+gccrs@kataplop.net, Lishin Subject: [gccrs COMMIT 2/2] gccrs: Emit drops for function parameters Date: Wed, 8 Jul 2026 10:06:17 +0000 Message-ID: <20260708100618.3141-2-gerris.rs@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260708100618.3141-1-gerris.rs@gmail.com> References: <20260708100618.3141-1-gerris.rs@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Lishin Add function parameters to the function scope drop list after the function body block is created. This makes parameters drop after local variables on normal function exit. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function): Track droppable function parameters in the function scope. gcc/testsuite/ChangeLog: * rust/execute/drop-function-params.rs: New test. Signed-off-by: Lishin --- This change was merged into the gccrs repository and is posted here for upstream visibility and potential drive-by review, as requested by GCC release managers. Each commit email contains a link to its details on github from where you can find the Pull-Request and associated discussions. Commit on github: https://github.com/Rust-GCC/gccrs/commit/76397e896150e3bf04567fc8df45ef780df4e501 The commit has NOT been mentioned in any issue. The commit has been mentioned in the following pull-request(s): - https://github.com/Rust-GCC/gccrs/pull/4591 gcc/rust/backend/rust-compile-base.cc | 13 ++++- .../rust/execute/drop-function-params.rs | 52 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/execute/drop-function-params.rs diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 4e618243b..04696787e 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -21,6 +21,7 @@ #include "rust-compile-stmt.h" #include "rust-compile-expr.h" #include "rust-compile-drop.h" +#include "rust-compile-drop-builder.h" #include "rust-compile-fnparam.h" #include "rust-compile-var-decl.h" #include "rust-compile-type.h" @@ -739,7 +740,7 @@ HIRCompileBase::compile_function_body (tree fndecl, // just add the stmt expression ctx->add_statement (return_value); - CompileDrop::emit_current_scope_drop_calls (ctx); + CompileDrop (ctx).emit_current_scope_drop_calls (); // now just return unit expression tree unit_expr = unit_expression (locus); @@ -845,6 +846,7 @@ HIRCompileBase::compile_function ( // setup the params TyTy::BaseType *tyret = fntype->get_return_type (); std::vector param_vars; + std::vector param_drop_candidates; if (self_param) { rust_assert (fntype->is_method ()); @@ -880,6 +882,11 @@ HIRCompileBase::compile_function ( const HIR::Pattern ¶m_pattern = referenced_param.get_param_name (); ctx->insert_var_decl (param_pattern.get_mappings ().get_hirid (), compiled_param_var); + + if (CompileDrop (ctx).type_has_drop_impl (param_tyty)) + param_drop_candidates.emplace_back ( + param_pattern.get_mappings ().get_hirid (), + param_pattern.get_locus ()); } if (!Backend::function_set_parameters (fndecl, param_vars)) @@ -893,6 +900,10 @@ HIRCompileBase::compile_function ( start_location, end_location); ctx->push_block (code_block); + DropBuilder drop_builder (*ctx); + for (auto &candidate : param_drop_candidates) + drop_builder.note_simple_drop_candidate (candidate.hirid, candidate.locus); + Bvariable *return_address = nullptr; tree return_type = TyTyResolveCompile::compile (ctx, tyret); diff --git a/gcc/testsuite/rust/execute/drop-function-params.rs b/gcc/testsuite/rust/execute/drop-function-params.rs new file mode 100644 index 000000000..c538922f5 --- /dev/null +++ b/gcc/testsuite/rust/execute/drop-function-params.rs @@ -0,0 +1,52 @@ +// { dg-output "l\r*\np\r*\nl\r*\np\r*\n" } +// { dg-additional-options "-w" } +#![feature(no_core)] +#![feature(lang_items)] +#![no_core] + +extern "C" { + fn printf(s: *const i8, ...); +} + +#[lang = "sized"] +pub trait Sized {} + +#[lang = "drop"] +pub trait Drop { + fn drop(&mut self); +} + +struct ParamDroppable; +struct LocalDroppable; + +impl Drop for ParamDroppable { + fn drop(&mut self) { + let msg = "p\n\0" as *const str as *const i8; + unsafe { + printf(msg); + } + } +} + +impl Drop for LocalDroppable { + fn drop(&mut self) { + let msg = "l\n\0" as *const str as *const i8; + unsafe { + printf(msg); + } + } +} + +fn named_param(_p: ParamDroppable) { + let _l = LocalDroppable; +} + +fn wildcard_param(_: ParamDroppable) { + let _l = LocalDroppable; +} + +fn main() -> i32 { + named_param(ParamDroppable); + wildcard_param(ParamDroppable); + 0 +} \ No newline at end of file