* [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada
@ 2022-10-24 8:54 Eric Botcazou
2022-11-17 21:02 ` Ramana Radhakrishnan
0 siblings, 1 reply; 3+ messages in thread
From: Eric Botcazou @ 2022-10-24 8:54 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 823 bytes --]
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 <ebotcazou@adacore.com>
* config/arm/arm.cc (arm_attribute_table) <cmse_nonsecure_call>: Change
decl_required field to false.
(arm_handle_cmse_nonsecure_call): Deal with a TYPE node.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 2356 bytes --]
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)
[-- Attachment #3: p.ads --]
[-- Type: text/x-adasrc, Size: 239 bytes --]
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;
[-- Attachment #4: p.adb --]
[-- Type: text/x-adasrc, Size: 122 bytes --]
package body P is
procedure Call (Proc : Non_Secure) is
begin
Proc.all;
end;
procedure Foo is null;
end P;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada
2022-10-24 8:54 [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada Eric Botcazou
@ 2022-11-17 21:02 ` Ramana Radhakrishnan
2022-11-21 8:51 ` Eric Botcazou
0 siblings, 1 reply; 3+ messages in thread
From: Ramana Radhakrishnan @ 2022-11-17 21:02 UTC (permalink / raw)
To: Eric Botcazou; +Cc: gcc-patches
On Mon, Oct 24, 2022 at 9:55 AM Eric Botcazou via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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?
>
Ok if no regressions, perhaps the test needs to be in the ada test suite ?
regards
Ramana
>
> 2022-10-24 Eric Botcazou <ebotcazou@adacore.com>
>
> * config/arm/arm.cc (arm_attribute_table) <cmse_nonsecure_call>: Change
> decl_required field to false.
> (arm_handle_cmse_nonsecure_call): Deal with a TYPE node.
>
>
> --
> Eric Botcazou
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada
2022-11-17 21:02 ` Ramana Radhakrishnan
@ 2022-11-21 8:51 ` Eric Botcazou
0 siblings, 0 replies; 3+ messages in thread
From: Eric Botcazou @ 2022-11-21 8:51 UTC (permalink / raw)
To: Ramana Radhakrishnan; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 214 bytes --]
> Ok if no regressions, perhaps the test needs to be in the ada test suite ?
Thanks. Sure, testcase added to gnat.dg like so:
* gnat.dg/machine_attr2.ads, gnat.dg/machine_attr2.adb: New test.
--
Eric Botcazou
[-- Attachment #2: machine_attr2.ads --]
[-- Type: text/x-adasrc, Size: 188 bytes --]
package Machine_Attr2 is
type Non_Secure is access procedure;
pragma Machine_Attribute (Non_Secure, "cmse_nonsecure_call");
procedure Call (Proc : Non_Secure);
end Machine_Attr2;
[-- Attachment #3: machine_attr2.adb --]
[-- Type: text/x-adasrc, Size: 354 bytes --]
-- { dg-do compile { target arm*-*-* } }
-- { dg-options "-mcpu=cortex-m33 -mcmse" }
package body Machine_Attr2 is
procedure Call (Proc : Non_Secure) is
begin
Proc.all;
end;
procedure Foo; -- { dg-warning "only applies to base type" }
pragma Machine_Attribute (Foo, "cmse_nonsecure_call");
procedure Foo is null;
end Machine_Attr2;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-21 8:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24 8:54 [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada Eric Botcazou
2022-11-17 21:02 ` Ramana Radhakrishnan
2022-11-21 8:51 ` Eric Botcazou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).