From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 24037383907A for ; Tue, 21 Feb 2023 12:04:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24037383907A 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-x42e.google.com with SMTP id t13so4090251wrv.13 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=ofZHKSXEGSLJ6XLMI/ob/BU2enTMuGPKclj1hZNENLCbcpe51xFeJVKnAAFTtOjvAF lgF2en0U5xKddN1msTFzpIV25ya/VMFsffxLFycKMhxI5BxGJ54zPBBrmNWUw7XOCmxq 8EgBBI9WnGyoH1vrvjCmbLirdER9+6dDHlxriWlzRG7yVGIPU9ITEhBVyl6Wh9eGZFdH sVYN+TMggAttac2y0l7/xUewOPxFki0yj/QnKFriT7q2wN16tYXoMzI9IyyukoWBndUe KyAV469FCpCFCrlA6Dhwr0yKr2tPva+asflhM1PnSqGw6i5iX7EXzSDla4aMm09gfDbI 1w8Q== X-Gm-Message-State: AO0yUKVD8Mx8JdzXP7jNyGdVAotGN/PdA47bXGruiWTXR85FqU8lOs7J cp481996/pS+3VuNFZ6Wp1/lxJc/9E8xYOTPmw== X-Google-Smtp-Source: AK7set/2p2eBiwfMbMIbGKPQ4fd8Hl2a9JXZfCkcyDjoCp7D4RQfLJTW+sUdhKy52o6roib/sRJFyQ== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.8 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 { -- 2.39.1