From patchwork Tue Feb 21 12:01:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837647wrn; Tue, 21 Feb 2023 04:38:49 -0800 (PST) X-Google-Smtp-Source: AK7set/BYL8Q6Dhl490MiAaqH9sw7bCW40WSsIqxWy2nOMBnhk//OXXVIQOpfx9X3HIkSTecY2oD X-Received: by 2002:aa7:db56:0:b0:4ad:a70c:e010 with SMTP id n22-20020aa7db56000000b004ada70ce010mr5540239edt.41.1676983129843; Tue, 21 Feb 2023 04:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983129; cv=none; d=google.com; s=arc-20160816; b=Urnl7hN0UuG3A8t0K3xdhcwl3el8Qa9/jtV8G8o429y9Zp+Ar7K6mu4kDuhuWQ/GQy Tsd4Qg3MB3UfIsK2rr4VyU8W6un2OzSlkOwrHgpM8a4bNwjWKqdrcXUuSBSeohNTtVer TeMCfA7rNUHBc/SStw+QV6fmsHgVP60WlJWOXWHXoywd8ng8sXiXw7WWzMTcu/tsd6Jl rlHBr7IsWiYx1r282qNIpoPOZHTeQRdVWEY/w5NgZWANgDKEgOk+Gl7OYfY+Y68ON+DJ 9P2ZlzkvlACU7uC1z5Sj6d3CTb8jfYDB59bhIcnEnHMGf6wwnq/7mMjkV3rGT/3RKCBa r8+A== 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=y4Ixa1KGj7wRHLUrMUNq040LE267nvqwm94j+ZxQG/A=; b=NzwSo6cyt7tB5XzcXqx5AyZB1qAgeq3ZETm1K+BQHSx/KhYKx9AfuLoGiKA/deO8Ia GoB1jBnoswv2m+jxBv9TqU0AXOz2G6o9h6FXX3wzYdHehzWGs6sSa0zn+BKOaI2usMxT rh2EBeY0IEqXodjeoQ2S+lOKmn48/HlaU1YvVqXJXrSVPWjR4zURNDxUjkDNpILUnZ1f ScuzgtE7Do3v5mxASGXzticbTC2fs/N7WSQsvEqvpVhDL31sQgarBOZN+3Aqr0GURnB8 Mggz8qnPtBojzMUi6zvIxZcVsBJQPGKLYMhkjNeXn7iSrr9uvr+/eCf6GgYpZxOcX9jB El6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="WPE/F7L2"; 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 l13-20020aa7c30d000000b004ace0fce45asi18250259edq.509.2023.02.21.04.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:38:49 -0800 (PST) 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="WPE/F7L2"; 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 DDDCE38E8177 for ; Tue, 21 Feb 2023 12:13:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 6D26A3836E9B for ; Tue, 21 Feb 2023 12:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D26A3836E9B 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-wr1-x435.google.com with SMTP id r7so3992476wrz.6 for ; Tue, 21 Feb 2023 04:04:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; 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=y4Ixa1KGj7wRHLUrMUNq040LE267nvqwm94j+ZxQG/A=; b=WPE/F7L2Bmm1m38Xrx7lQJWiBLovglHyBqrDSXx3QcywZWwp78AXm9ci5NYL3dlH+g RJkW13VvT6SuRUsB6HgAoDOYMxNwFgeUulYdK2JcESqANWDWSpKXES8+eBBIzHDeYbVp fUtqsjlaqQ3HQqQx40o+WLqXWSLZVOyxBS4wxkWkaaCH0tmRNK4ZOEMpR4lCHAfusiwx +Ow9RJ5nt6dp6tBukhL7xWTH4a/9vYE5D81+5Jdgq4lPSjC5WeOWJFLcPL6aXP4Br6+e Dh5tqBzO7cXqzOohxJUzvoA2tR8SKpIBNINgM8ePI2ADmdsXmjAqe3ZhsuHBsFb7YKjH +IKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=y4Ixa1KGj7wRHLUrMUNq040LE267nvqwm94j+ZxQG/A=; b=TD57b9ned6gBOa/tdu+RWzKigUEC0WZnp8w3SytFDFEYYrhZsK+EJ+ou/JAk/hDmRl bPyi1OrkVic0+qztTeN75iqVw/NmtxKt9Rz2KfcKMBq10TEzU5KYprDfNTicZMycZouP XpJmg9a5NiKRODITIT4mMyM56yKldlfeVEtE01yUzRMh6TzSWZuil5coECQKBGJPcBAF OxwhyHknXm7JkaMyM184V8ANfLVv9GBB6Cr84yjJQMcERjTdZmUt1gLnapzfdZaB8az5 TBMrmRLQkQeoufnIh0Z/IhxSOwQ5q/nZ/bLoq2wV77a1YbJe4Jt4W0C7isWtU2C74vsw +zkQ== X-Gm-Message-State: AO0yUKV8sD6NmRVOBPR07/UD/BawDpHqoZOcAIkTX9iQrHC2+zoFTjmc awhs+Zt+fKdQDtiG3mhrLh8QRIFbLzxr3vzagw== X-Received: by 2002:adf:e805:0:b0:2c6:e670:8867 with SMTP id o5-20020adfe805000000b002c6e6708867mr4219103wrm.0.1676981054036; Tue, 21 Feb 2023 04:04:14 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 063/103] gccrs: intrinsics: Cleanup error handling around atomic_store_* Date: Tue, 21 Feb 2023 13:01:53 +0100 Message-Id: <20230221120230.596966-64-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.3 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 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758444262444569752?= X-GMAIL-MSGID: =?utf-8?q?1758444262444569752?= From: Arthur Cohen gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (check_for_basic_integer_type): New function. (build_atomic_builtin_name): Use HIR Type instead of `tree`. (atomic_store_handler_inner): Cleanup error handling. (unchecked_op_inner): Likewise. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-5.rs: Fix error message. --- gcc/rust/backend/rust-compile-intrinsic.cc | 50 +++++++++++-------- .../rust/compile/torture/intrinsics-5.rs | 4 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 142a2173672..b0c6015bee2 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -50,6 +50,22 @@ is_basic_integer_type (TyTy::BaseType *type) } } +static bool +check_for_basic_integer_type (const std::string &intrinsic_str, Location locus, + TyTy::BaseType *type) +{ + auto is_basic_integer = is_basic_integer_type (type); + if (!is_basic_integer) + { + rust_error_at ( + locus, + "%s intrinsics can only be used with basic integer types (got %qs)", + intrinsic_str.c_str (), type->get_name ().c_str ()); + } + + return is_basic_integer; +} + static tree offset_handler (Context *ctx, TyTy::FnType *fntype); static tree @@ -652,7 +668,7 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) } static std::string -build_atomic_builtin_name (Location locus, tree operand_type) +build_atomic_builtin_name (Location locus, TyTy::BaseType *operand_type) { static const std::map allowed_types = { {"i8", "1"}, {"i16", "2"}, {"i32", "4"}, {"i64", "8"}, @@ -665,7 +681,7 @@ build_atomic_builtin_name (Location locus, tree operand_type) std::string result = "atomic_store_"; - auto type_name = std::string (TYPE_NAME_STRING (operand_type)); + auto type_name = operand_type->get_name (); if (type_name == "usize" || type_name == "isize") { rust_sorry_at ( @@ -673,21 +689,10 @@ build_atomic_builtin_name (Location locus, tree operand_type) return ""; } - // FIXME: Can we have a better looking name here? - // Instead of `::::`? - // Maybe instead of giving the tree node, pass the resolved Tyty before it - // gets compiled? - // - // Or should we perform this check somwhere else in the compiler? auto type_size_str = allowed_types.find (type_name); - if (type_size_str == allowed_types.end ()) - { - rust_error_at (locus, - "atomic intrinsics are only available for basic integer " - "types: got type %qs", - type_name.c_str ()); - return ""; - } + + if (!check_for_basic_integer_type ("atomic", locus, operand_type)) + return ""; result += type_size_str->second; @@ -726,8 +731,11 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) auto value = ctx->get_backend ()->var_expression (param_vars[1], Location ()); auto memorder = make_unsigned_long_tree (ctx, ordering); + auto monomorphized_type + = fntype->get_substs ()[0].get_param_ty ()->resolve (); + auto builtin_name - = build_atomic_builtin_name (fntype->get_locus (), TREE_TYPE (types[0])); + = build_atomic_builtin_name (fntype->get_locus (), monomorphized_type); if (builtin_name.empty ()) return error_mark_node; @@ -781,11 +789,9 @@ unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op) auto *monomorphized_type = fntype->get_substs ().at (0).get_param_ty ()->resolve (); - if (!is_basic_integer_type (monomorphized_type)) - rust_error_at (fntype->get_locus (), - "unchecked operation intrinsics can only be used with " - "basic integer types (got %qs)", - monomorphized_type->get_name ().c_str ()); + + check_for_basic_integer_type ("unchecked operation", fntype->get_locus (), + monomorphized_type); auto expr = build2 (op, TREE_TYPE (x), x, y); auto return_statement diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs index e0087720cc4..7fd84dcd635 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs @@ -2,8 +2,8 @@ trait Copy {} extern "rust-intrinsic" { pub fn atomic_store_seqcst(dst: *mut T, value: T); - // { dg-error "atomic intrinsics are only available for basic integer types: got type .intrinsics_5::VeryLargeType." "" { target *-*-* } .-1 } - // { dg-error "atomic intrinsics are only available for basic integer types: got type .bool." "" { target *-*-* } .-2 } + // { dg-error "atomic intrinsics can only be used with basic integer types .got .VeryLargeType.." "" { target *-*-* } .-1 } + // { dg-error "atomic intrinsics can only be used with basic integer types .got .bool.." "" { target *-*-* } .-2 } } struct VeryLargeType {