Message ID | 20230405140411.3016563-67-arthur.cohen@embecosm.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp357156vqo; Wed, 5 Apr 2023 07:38:28 -0700 (PDT) X-Google-Smtp-Source: AKy350agVWwjWunGWWr6+Tog0Hfz5fzUOd6gGGh/lS4PI//WqUqFiZeT8Awz5gpWVQPF2HpkKRYl X-Received: by 2002:aa7:c583:0:b0:501:d18f:af83 with SMTP id g3-20020aa7c583000000b00501d18faf83mr2043132edq.8.1680705508719; Wed, 05 Apr 2023 07:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705508; cv=none; d=google.com; s=arc-20160816; b=Fjg6HCHYADGWTr0eT0ysSdOOIsnZMW/joLsNfl98/sF+FtOAZg4pAO9IRi6TnD17Xf w8mJ+5gCyGRFdDT0R72fuq7jiBvv/mok+6JBuktDLssEcGzxyO+KoJgfz8amREzszPIo 4nDddz9XBLwoOj2N6ENlov9Q36lATaQr2K2XaLejHFQ8oRq3PiAkp9DAgn0FONmKRXeB m0JybzJHwPFfRhCm0nV6sUhGojan6uAMligNjWTPCrpoZj6qJN8N7gDspoZqJbi4vOTx RMH+s5mZtGS+Aa3xYIX5Awd5BoKEHUQO1wHIiNLNwoAEO7Kswl9QqYxS8pa9hgdPkpBG Z4HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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:dmarc-filter :delivered-to; bh=62Q4BK9iHnz4xCrdVNcfpSpma623JkkizKxhTXvFuxo=; b=azSDeSuZpOQRhnuqnouzhIKvAHpGrOUshyUVYv3r9t79mBujSR7wOrpFc/l4Uj3spD PmM5mIookDobe0BRWo2wanvY09Y5l7cDdi09oMRfyFkOCbDLXkaYEQoFTqd2HuTqRkFR PmAXKRjAvdKqN2vHmNZw+pK2KcghdKMB+ubmi8K/39kwa5okmiiM+btXWgQWjDfKa86S 55yhn+YRWOCtiNirwNJ+QRzueR33D2c3IsDe4F/I2GORcogHsarEfQiy29Y/k6itVyAc bo3BVGikziv2BNIKLwRSc91oorLVdcWwp+ULPkAYifHrIvr0pehTSgcbpynMYMRpipfL HYmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TKhepjF1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r9-20020aa7cb89000000b00502961db46dsi8498128edt.268.2023.04.05.07.38.28 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:38:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TKhepjF1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B48BD382AA69 for <ouuuleilei@gmail.com>; Wed, 5 Apr 2023 14:14:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 2431C3856DE5 for <gcc-patches@gcc.gnu.org>; Wed, 5 Apr 2023 14:06:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2431C3856DE5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x334.google.com with SMTP id n19so20972379wms.0 for <gcc-patches@gcc.gnu.org>; Wed, 05 Apr 2023 07:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703574; 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=62Q4BK9iHnz4xCrdVNcfpSpma623JkkizKxhTXvFuxo=; b=TKhepjF1ERAILhB8LqATk8ENojVhYm3fpTy1t5t+VTWEnYaR338J8Jk07fjbjbW/p0 5YP3qg6wAc9epRF9xbFeLUJxCRsI4QnIa5KZaeYeSbr83baMUkjIOuYYHeEhAnjyaBVu ANciYsgGcR6ZlKTLrxyoUndiETrY3vvO3EDMcEYxd0tN1Ki4I3ArWQIB+ZtTrKzK+Q8e sWU8js4Fi6hwGOYWbaYAZKTA2gnXIMe9r8LHaI46fOQghAWzKuK5DYSy5Ha8WuNYAYF2 CVP7aKWmwe1pp0YqO+w/UX3xe/mEZG9+kS0V06Zb0M9g/i7qQiCwvFzrzcSRnBqnbCz7 z7dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703574; 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=62Q4BK9iHnz4xCrdVNcfpSpma623JkkizKxhTXvFuxo=; b=Gi0I2KA42jc2GhNyYCtimHTzGL6sstpFnk6fNpKP7jQJfbCZ+KJaSdz6u/49qh3sSK lYr8MEWUkgJIIcis2TAO5bDsazK2cgllD+FFkCHk2d4ADAkW779Wpdc4CPdxcfeXZnoR k29JWv2FWEm1mXRt3IuSdT91NfuTPcAhjhdlT66qBDYxwN+77kra3kcI02+dMaf9k2zl fWhihvjvVTahrEkcyOx5aUn3/en7AZMGVYPv8vg9CZ3CNlzc1JhbcnrdKj6MUVgfseQa jREue2+AUFp0aYMP/nNp7frHVEFKpMHBiccTd11P9+oWIl5vmAIybnGPFVVwATgN54uQ 7vYg== X-Gm-Message-State: AAQBX9deWL5zpp7BG7ycpIchjwwl+xJy3ifZ4FcDHZZWeS1suUCMrZwz AAjQ0p6NWJzSY1RxLUqkvgUOwTWteNyeJQewIw== X-Received: by 2002:a7b:c38a:0:b0:3ea:e834:d0d1 with SMTP id s10-20020a7bc38a000000b003eae834d0d1mr4863077wmj.36.1680703574368; Wed, 05 Apr 2023 07:06:14 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:14 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery <powerboat9.gamer@gmail.com> Subject: [committed 66/88] gccrs: Add variadic argument type checking Date: Wed, 5 Apr 2023 16:03:50 +0200 Message-Id: <20230405140411.3016563-67-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.6 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 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <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>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762347459290061542?= X-GMAIL-MSGID: =?utf-8?q?1762347459290061542?= |
Series |
[committed,01/88] gccrs: fatal_error_flag: Fix typo in error message
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Arthur Cohen
April 5, 2023, 2:03 p.m. UTC
From: Owen Avery <powerboat9.gamer@gmail.com> gcc/rust/ChangeLog: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Add variadic argument type checking. (TypeCheckCallExpr::visit): Fix comment spelling ("varadic"). gcc/testsuite/ChangeLog: * rust/execute/torture/overflow1.rs: Fix test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com> --- gcc/rust/typecheck/rust-tyty-call.cc | 56 ++++++++++++++++++- .../rust/execute/torture/overflow1.rs | 2 +- 2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 67e2866cbce..f0846ae25ec 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -122,7 +122,7 @@ TypeCheckCallExpr::visit (FnType &type) return; } - // it might be a varadic function + // it might be a variadic function if (i < type.num_params ()) { auto fnparam = type.param_at (i); @@ -143,6 +143,60 @@ TypeCheckCallExpr::visit (FnType &type) return; } } + else + { + switch (argument_expr_tyty->get_kind ()) + { + case TyTy::TypeKind::ERROR: + return; + case TyTy::TypeKind::INT: { + auto &int_ty + = static_cast<TyTy::IntType &> (*argument_expr_tyty); + if ((int_ty.get_int_kind () == TyTy::IntType::IntKind::I8) + || (int_ty.get_int_kind () == TyTy::IntType::IntKind::I16)) + { + rust_error_at (arg_locus, + "expected %<c_int%> variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::UINT: { + auto &uint_ty + = static_cast<TyTy::UintType &> (*argument_expr_tyty); + if ((uint_ty.get_uint_kind () == TyTy::UintType::UintKind::U8) + || (uint_ty.get_uint_kind () + == TyTy::UintType::UintKind::U16)) + { + rust_error_at (arg_locus, + "expected %<c_uint%> variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::FLOAT: { + if (static_cast<TyTy::FloatType &> (*argument_expr_tyty) + .get_float_kind () + == TyTy::FloatType::FloatKind::F32) + { + rust_error_at (arg_locus, + "expected %<c_double%> variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::BOOL: + rust_error_at (arg_locus, "expected %<c_int%> variadic argument"); + return; + case TyTy::TypeKind::FNDEF: + rust_error_at (arg_locus, + "unexpected function definition type as variadic " + "argument - cast to function pointer"); + return; + default: + break; + } + } i++; } diff --git a/gcc/testsuite/rust/execute/torture/overflow1.rs b/gcc/testsuite/rust/execute/torture/overflow1.rs index 57a0824ce0a..c4ccab1a133 100644 --- a/gcc/testsuite/rust/execute/torture/overflow1.rs +++ b/gcc/testsuite/rust/execute/torture/overflow1.rs @@ -16,5 +16,5 @@ fn main() { // { dg-final { scan-tree-dump ADD_OVERFLOW original } } let c = a + b; - unsafe { printf("%d\n\0" as *const str as *const i8, c) } + unsafe { printf("%d\n\0" as *const str as *const i8, c as i32) } }