From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 76B45385840A for ; Mon, 24 Oct 2022 08:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 76B45385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x430.google.com with SMTP id k8so6334124wrh.1 for ; Mon, 24 Oct 2022 01:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=UB8/VB32GN/NW8zvRd6fgSsRgiA8CNtQuEXBVif3EDA=; b=fBIehCAfsMAbnZW2LsyKz6mE3Gk4xGg1sBP/ib8jEBl+BlPMY9gi7ztSKw5ro1qZSA KwdbC+wehyhG9/P9SrXBbTcKFu7XfUSumfEUIdn4tNXi7aCpvBOCrfPNdW3c9dGMv4ig 5Dbx2cHoLxe2MiPoRHOM8pKD497lkbCSpklvtsesh0o3KIDDJ1L7fu6wbU4gp77asjJa HOJhM+EhBkVn11wP1uvT4LMjqp7K1HvWqCQ9/dQSIIw1mxLD3yY8F5KEr16+QE24egcL eUfDXIxKVajJG23E95cQWkiIYwYK94K+BS2FOeJiuZkCtfJ4HhbiHEkiUZaKMluzrCY7 QNRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UB8/VB32GN/NW8zvRd6fgSsRgiA8CNtQuEXBVif3EDA=; b=dPbryHX9lXGssnx+g3flgYsDYc7ardl3at/onjrqPevw9ursEDt8i3zQuSe/bPjU8h D4rSBqqL5DLGdqLlHsqGAB9txfm10vrGoVU00dv2/p9FbvN6BTG4kL0xcI5meUwrVGlh yBCM/545Tn7T9XMWUtqm57+JAoRLvzRaNrj3y3T8FnT+tIOVAQiSZe9s6QtGarBZ1UAk mYX+83ZSXPxochauWCEVxi8wisBug4uwD8i76nSteqWwaULHzEofNfkrjNO90/0d247w r+Vhwv+Q6zxqHzNKQcQKTwym5As8EUbhh8xRKob902GNWpgeM+Z4wHg+OciN8LMRt2YA OftA== X-Gm-Message-State: ACrzQf0u/5UBbpYbHYo1kdyp90veBYBUhdcujowgiMQBp240NneGdqou c42KB+yyX3amjBDTSkslpUTrPskexUQsdQ== X-Google-Smtp-Source: AMsMyM7cgewPR6bnKRjs1FHT3V2VdeOq/x2JiS9/b7UqLyICz+Hn86g1t+OfFm6J8MwXe+3lLtINSQ== X-Received: by 2002:a05:6000:d:b0:236:6662:5bb9 with SMTP id h13-20020a056000000d00b0023666625bb9mr5478796wrx.619.1666601697172; Mon, 24 Oct 2022 01:54:57 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id j5-20020a05600c488500b003c6c4639ac6sm9925107wmp.34.2022.10.24.01.54.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 01:54:56 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada Date: Mon, 24 Oct 2022 10:54:55 +0200 Message-ID: <3519176.R56niFO833@fomalhaut> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3642007.MHq7AAxBmi" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-10.9 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: This is a multi-part message in MIME format. --nextPart3642007.MHq7AAxBmi Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, until most other machine attributes, this one does not work in Ada because, while it applies to pointer-to-function types, it is explicitly marked as requiring declarations in the implementation. Now, in Ada, machine attributes are specified like this: type Non_Secure is access procedure; pragma Machine_Attribute (Non_Secure, "cmse_nonsecure_call"); i.e. not attached to the declaration of Non_Secure (testcase attached). So the attached patch extends the support to Ada by also accepting pointer-to-function types in the handler. Tested on arm-eabi, OK for the mainline? 2022-10-24 Eric Botcazou * config/arm/arm.cc (arm_attribute_table) : Change decl_required field to false. (arm_handle_cmse_nonsecure_call): Deal with a TYPE node. -- Eric Botcazou --nextPart3642007.MHq7AAxBmi Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="p.diff" diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index ee8f1babf8a..fc96ed9cce4 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -375,7 +375,7 @@ static const struct attribute_spec arm_attribute_table[] = /* ARMv8-M Security Extensions support. */ { "cmse_nonsecure_entry", 0, 0, true, false, false, false, arm_handle_cmse_nonsecure_entry, NULL }, - { "cmse_nonsecure_call", 0, 0, true, false, false, true, + { "cmse_nonsecure_call", 0, 0, false, false, false, true, arm_handle_cmse_nonsecure_call, NULL }, { "Advanced SIMD type", 1, 1, false, true, false, true, NULL, NULL }, { NULL, 0, 0, false, false, false, false, NULL, NULL } @@ -7605,8 +7605,8 @@ arm_handle_cmse_nonsecure_call (tree *node, tree name, int /* flags */, bool *no_add_attrs) { - tree decl = NULL_TREE, fntype = NULL_TREE; - tree type; + tree decl = NULL_TREE; + tree fntype, type; if (!use_cmse) { @@ -7616,16 +7616,20 @@ arm_handle_cmse_nonsecure_call (tree *node, tree name, return NULL_TREE; } - if (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == TYPE_DECL) + if (DECL_P (*node)) { - decl = *node; - fntype = TREE_TYPE (decl); + fntype = TREE_TYPE (*node); + + if (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == TYPE_DECL) + decl = *node; } + else + fntype = *node; - while (fntype != NULL_TREE && TREE_CODE (fntype) == POINTER_TYPE) + while (fntype && TREE_CODE (fntype) == POINTER_TYPE) fntype = TREE_TYPE (fntype); - if (!decl || TREE_CODE (fntype) != FUNCTION_TYPE) + if ((DECL_P (*node) && !decl) || TREE_CODE (fntype) != FUNCTION_TYPE) { warning (OPT_Wattributes, "%qE attribute only applies to base type of a " "function pointer", name); @@ -7640,10 +7644,17 @@ arm_handle_cmse_nonsecure_call (tree *node, tree name, /* Prevent trees being shared among function types with and without cmse_nonsecure_call attribute. */ - type = TREE_TYPE (decl); + if (decl) + { + type = build_distinct_type_copy (TREE_TYPE (decl)); + TREE_TYPE (decl) = type; + } + else + { + type = build_distinct_type_copy (*node); + *node = type; + } - type = build_distinct_type_copy (type); - TREE_TYPE (decl) = type; fntype = type; while (TREE_CODE (fntype) != FUNCTION_TYPE) --nextPart3642007.MHq7AAxBmi Content-Disposition: attachment; filename="p.ads" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="utf-8"; name="p.ads" package P is type Non_Secure is access procedure; pragma Machine_Attribute (Non_Secure, "cmse_nonsecure_call"); procedure Call (Proc : Non_Secure); procedure Foo; pragma Machine_Attribute (Foo, "cmse_nonsecure_call"); end P; --nextPart3642007.MHq7AAxBmi Content-Disposition: attachment; filename="p.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="utf-8"; name="p.adb" package body P is procedure Call (Proc : Non_Secure) is begin Proc.all; end; procedure Foo is null; end P; --nextPart3642007.MHq7AAxBmi--