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: 204213 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1028758dyc; Wed, 21 Feb 2024 05:18:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXI/9JkjjfK8zVIiLDsVvlHbJn5rYecUFSfbsLernhJt/L3n5yhaFbp6hvoFunr58Xb7Bn1X/oHbG2LjY14OFHqCETPVA== X-Google-Smtp-Source: AGHT+IG/AjZSgfPY25RmcV0DWnGPDbaGEjk22EseyupS4VqkZZYLGzPcZl0O2jdimt0GvFSj5rMI X-Received: by 2002:ac8:5a0e:0:b0:42c:3ebc:bda9 with SMTP id n14-20020ac85a0e000000b0042c3ebcbda9mr20856561qta.29.1708521521320; Wed, 21 Feb 2024 05:18:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708521521; cv=pass; d=google.com; s=arc-20160816; b=qPa63FFqZeUH/G62KhGw6G40nHLCn+JlkRo51YUeI8DcZp4Gz98jkDp4bdc0h1xbUA qH55LxisYtQCFWN/X1ndj12plIwZ9xwo7hIwXhjEOx3JTL/uPf+AzQ5NtpVnHAuqybgS VW25aHjnsyeMMV02PagpJRcAKG6C4DJmLciFgjaBnXWTsIW9PpNdvOON9bKLg13A2n30 YgKagoLmDcKmyAe95YqVSdf2sJOHUb755kXDQVAapdS2JOqyTK9Gn2w/ywxUYvj4YWBO 8STDaUuVSJFJrKVLy/YsSvg2urU+sJMtgeeemsNiqSpBEZ6bg0K4p+wa2gLf9J1gn4Xg c1+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=pAre2/8x/6dM4XODfbJTiUo/JqxSsvtagjXjkM9Ghf8=; fh=bRs0Yp85O7O0z1fYz+iYe57EZaQoVsxibyeiKdts6Wk=; b=EvLtT7tmheuibPMNEqFqsBiWIkZnaz7b9SuYeJlGKw66ms7c6CU/lUiU4Jy5VHskAx NQSAszjmAM2AF3mp4caKYZn2dYmJyegtJCoDrdXwb9nb0WrINI1WFk8o1y5guq+MD5Lw 68+995oxVEMtlwNpzSU7qwXUv+3UtYlOU+ACg5s6zhY0rNASUkBH8hRR+rrdSTkVdcRC 1MfvdMvl0WqGLtv0VxfK+uC6VythMaRd74IbG/for05GizbMqW0+Y+R2TnKUPr8swaLh FLahwQZZ4OO2FQkbMGTJLXKfpg6v4UeF2olJjuVUMj4jG+lnx9cMZ0IW6suxoit5/Pew Uw0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=UfWtlCBl; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q24-20020ac84518000000b0042e3c93b99esi618221qtn.91.2024.02.21.05.18.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 05:18:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=UfWtlCBl; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58D3B38582A5 for ; Wed, 21 Feb 2024 13:18:40 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791514663063992852 X-GMAIL-MSGID: 1791514663063992852 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