From patchwork Wed Feb 21 13:15:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 86158 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBEC23858439 for ; Wed, 21 Feb 2024 13:18:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 16B33385842E for ; Wed, 21 Feb 2024 13:16:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16B33385842E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16B33385842E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708521394; cv=none; b=SyEr9v1G/jJCa9epAU8vU0qdEGBxJUwWe+MUZE70BgKClyLx8AlQAfFRB/BkHiAfj5Rcz8Yo/8D8VtWM4gLRflTj1npp9qUDpN3IpPpEObi8xU8OPTgZy/+Qd3q9s4xQEJ1HGzCZ4MDDkqf9JDySn89kZDaAhIEpK0CV9SOHoeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708521394; c=relaxed/simple; bh=mVoPFeT+3g3moyP+TPJm8W/x4Bo99YiIJi9cNQPzhwk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uzwrWck13c94X1FsZIpue/WoP5hxObTFrEN+BmB5MKBIRbhyUpGXioQtzjqc5EJxC2c7JZrDdZ0LqpuR4J7tkaBHlwyTct+bjWZ86nqix2oYl8Ul4lELbLaP0EE411uB7F0J+V/TLwLAVcTexLlVTXn3SLAaOAKpdbzkNuF+9RY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-512b42b6697so4034202e87.1 for ; Wed, 21 Feb 2024 05:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1708521390; x=1709126190; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=pAre2/8x/6dM4XODfbJTiUo/JqxSsvtagjXjkM9Ghf8=; b=UfWtlCBl4feW7hcmAPz/ng0cO/1B9z6NsmpIbvWG7tPXDuAVULlU1USvXv88Kt2y09 0szgkFL4nziQOSDGkUEaia23KpE6YMEBiCDhZGM1E3TlL34jJBs93CQO8wFcDTablvAY Aj2QewEFuOVGKys7zkU/lsQL6dkSB79WT5M+l9bV7d04q+ap8poX+GWx44U/1yQvpKhE t+Z2TBMClPKELqg9W5cbclpM7bviSOcesDaJAHtAZQHVT1NlfuGgq7aSAByfvD7iWQM+ OtXmBQr5S+6oi8Fh2kzfTHL9bG2GjHgWXky8aaSJs1ZcFmgWEIB0fkM3XSFLuhlq2ysp N6bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708521390; x=1709126190; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pAre2/8x/6dM4XODfbJTiUo/JqxSsvtagjXjkM9Ghf8=; b=r+b/2ti6UmOaE1oGbZ6i40iETijHVFyKxJaz4AodtLbyC0sFsVaxap3XP4Fa9vYmW9 vQyNVC3aVpvdb12Bukfo8RP+AkzzEUs+8QjPh4pDPuJpFxcn0wsYaMI7wVZXofC1CjRP KLAF0IiEMfkcrW+9XtN2UTto5evecC8I41vK1djAfPT2+p20TQYbPmCuQerMwWY/g0HL W4k8T6NpxUc1Rws/Bb5mAZWJHV+tID4NngLObK0NiuN0AAAX7eScPSBBYu49cbxfW1W0 qTfdkzpEz0nnytFJyKKshgfp4WZu8AA8XH9V5H+2oPy4AHLjVfkZqnzRrzyMR2Dza+0E kisA== X-Gm-Message-State: AOJu0YyOtfAOygJylQv41VHfRZMn9cDpdKAvIpLK4YD+Q6K2LGFb5r0p 4UA1Z9aLLX15alc7KrbMRHiWuXF+CSRqljnQl2qos8g+2sCZHTpR8RGoTgwsnAv5+0v+Wq77lfY = X-Google-Smtp-Source: AGHT+IH///03/pvGqcctp30VXsGSeqL6jQUWQvM7i15Q6HMEErIX+0GPN3rA1RN3QDTypNY/LNnJ1Q== X-Received: by 2002:ac2:58ea:0:b0:512:b84e:e7a1 with SMTP id v10-20020ac258ea000000b00512b84ee7a1mr4467487lfo.5.1708521389603; Wed, 21 Feb 2024 05:16:29 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id m12-20020a170906160c00b00a3d0a094574sm4927074ejd.66.2024.02.21.05.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 05:16:28 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, 0xn4utilus Subject: [COMMITTED 8/9] gccrs: Add variadic check on function params Date: Wed, 21 Feb 2024 14:15:26 +0100 Message-ID: <20240221131636.3336103-11-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240221131636.3336103-2-arthur.cohen@embecosm.com> References: <20240221131636.3336103-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org From: 0xn4utilus gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add variadic check on all parameters. gcc/testsuite/ChangeLog: * rust/compile/issue-2850.rs: New test. Signed-off-by: 0xn4utilus --- gcc/rust/checks/errors/rust-ast-validation.cc | 12 ++++++++---- gcc/testsuite/rust/compile/issue-2850.rs | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-2850.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index d57b7cb70fe..fcba57d0a92 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -132,10 +132,14 @@ ASTValidation::visit (AST::Function &function) rust_error_at (function.get_locus (), "free function without a body"); } - if (function.is_variadic ()) - rust_error_at ( - function.get_function_params ().back ()->get_locus (), - "only foreign or % functions may be C-variadic"); + auto &function_params = function.get_function_params (); + for (auto it = function_params.begin (); it != function_params.end (); it++) + { + if (it->get ()->is_variadic ()) + rust_error_at (it->get ()->get_locus (), + "only foreign or % functions may " + "be C-variadic"); + } AST::ContextualASTVisitor::visit (function); } diff --git a/gcc/testsuite/rust/compile/issue-2850.rs b/gcc/testsuite/rust/compile/issue-2850.rs new file mode 100644 index 00000000000..62cbe0f6524 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2850.rs @@ -0,0 +1,17 @@ +fn myfun0(...,_:i32) {} +// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 } + +fn myfun1(a:i32,...,_:i32) {} +// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 } + +struct z { + x: f64, + y: f64, +} + +impl z { + fn new(x: f64, ..., y: f64) -> z { + // { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 } + z { x: x, y: y } + } +} \ No newline at end of file