* [Arm][CMSE]Add warn_unused_return attribute to cmse functions
@ 2019-07-17 11:33 Joel Hutton
2019-07-31 8:58 ` Kyrill Tkachov
0 siblings, 1 reply; 2+ messages in thread
From: Joel Hutton @ 2019-07-17 11:33 UTC (permalink / raw)
To: GCC Patches; +Cc: nd
[-- Attachment #1: Type: text/plain, Size: 1449 bytes --]
At present it is possible to call the CMSE functions for checking
addresses (such as cmse_check_address_range) and forget to check/use
the return value. This patch makes the interfaces more robust against
programmer error by marking these functions with the warn_unused_result
attribute. With this set, any use of these functions that does not use
the result will produce a warning.
This produces a warning on default warn levels when the result of the
cmse functions is not used.
For the following function:
void foo()
{
int *data;
cmse_check_address_range((int*)data, 0, 0);
}
The following warning is emitted:
warning: ignoring return value of 'cmse_check_address_range' declared
with attribute 'warn_unused_result' [-Wunused-result]
6 | cmse_check_address_range((int*)data, 0, 0);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc/ChangeLog:
2019-07-10 Joel Hutton <Joel.Hutton@arm.com>
* config/arm/arm_cmse.h (cmse_nonsecure_caller): Add
warn_unused_result attribute.
(cmse_check_address_range): Add warn_unused_result attribute.
libgcc/ChangeLog:
2019-07-10 Joel Hutton <Joel.Hutton@arm.com>
* config/arm/cmse.c (cmse_check_address_range): Add
warn_unused_result attribute.
2019-07-10 Joel Hutton <Joel.Hutton@arm.com>
* gcc.target/arm/cmse/cmse-17.c: New test.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-CMSE-warn-unused-result.patch --]
[-- Type: text/x-patch; name="0001-CMSE-warn-unused-result.patch", Size: 2237 bytes --]
From 628070faaf157934e6b4c8d7d2d288244467bea6 Mon Sep 17 00:00:00 2001
From: Joel Hutton <Joel.Hutton@arm.com>
Date: Wed, 10 Jul 2019 09:59:58 +0100
Subject: [PATCH] CMSE warn unused result
---
gcc/config/arm/arm_cmse.h | 2 ++
gcc/testsuite/gcc.target/arm/cmse/cmse-17.c | 10 ++++++++++
libgcc/config/arm/cmse.c | 1 +
3 files changed, 13 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/arm/cmse/cmse-17.c
diff --git a/gcc/config/arm/arm_cmse.h b/gcc/config/arm/arm_cmse.h
index b543cbfe455ae57487be199f7c918eb87db30bf2..a72c46f1a954bd3ba4aefcdbb7a31085d0f583c0 100644
--- a/gcc/config/arm/arm_cmse.h
+++ b/gcc/config/arm/arm_cmse.h
@@ -164,6 +164,7 @@ __CMSE_TT_ASM (at)
/* FIXME: diagnose use outside cmse_nonsecure_entry functions. */
__extension__ static __inline int __attribute__ ((__always_inline__))
+__attribute__ ((warn_unused_result))
cmse_nonsecure_caller (void)
{
return __builtin_arm_cmse_nonsecure_caller ();
@@ -184,6 +185,7 @@ cmse_nonsecure_caller (void)
#define CMSE_MPU_READ 8
__extension__ void *
+__attribute__ ((warn_unused_result))
cmse_check_address_range (void *, size_t, int);
#define cmse_check_pointed_object(p, f) \
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c
new file mode 100644
index 0000000000000000000000000000000000000000..a2cce09afae590461b86397e73e9b98649bed95a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-mcmse"} */
+
+#include <arm_cmse.h>
+
+void foo()
+{
+ int *data;
+ cmse_check_address_range((int*)data, 0, 0); /* { dg-warning "ignoring return value" } */
+}
diff --git a/libgcc/config/arm/cmse.c b/libgcc/config/arm/cmse.c
index 34a46fde2d2fcd9dc181bf5a74dd698de2ebc9bd..0c5a3eaefab49ae07e67b82481fdd0d8dd100227 100644
--- a/libgcc/config/arm/cmse.c
+++ b/libgcc/config/arm/cmse.c
@@ -30,6 +30,7 @@
address range. See ACLE changes for ARMv8-M. */
void *
+__attribute__ ((warn_unused_result))
cmse_check_address_range (void *p, size_t size, int flags)
{
cmse_address_info_t permb, perme;
--
2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Arm][CMSE]Add warn_unused_return attribute to cmse functions
2019-07-17 11:33 [Arm][CMSE]Add warn_unused_return attribute to cmse functions Joel Hutton
@ 2019-07-31 8:58 ` Kyrill Tkachov
0 siblings, 0 replies; 2+ messages in thread
From: Kyrill Tkachov @ 2019-07-31 8:58 UTC (permalink / raw)
To: Joel Hutton, GCC Patches; +Cc: nd
Hi Joel,
On 7/17/19 12:19 PM, Joel Hutton wrote:
> At present it is possible to call the CMSE functions for checking
> addresses (such as cmse_check_address_range) and forget to check/use
> the return value. This patch makes the interfaces more robust against
> programmer error by marking these functions with the warn_unused_result
> attribute. With this set, any use of these functions that does not use
> the result will produce a warning.
>
> This produces a warning on default warn levels when the result of the
> cmse functions is not used.
>
> For the following function:
> void foo()
> {
> Â Â Â Â int *data;
> Â Â Â Â cmse_check_address_range((int*)data, 0, 0);
> }
> The following warning is emitted:
> warning: ignoring return value of 'cmse_check_address_range' declared
> with attribute 'warn_unused_result' [-Wunused-result]
> Â Â Â Â 6 |Â cmse_check_address_range((int*)data, 0, 0);
> Â Â Â Â Â Â Â |Â ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> gcc/ChangeLog:
>
> 2019-07-10 Joel Hutton <Joel.Hutton@arm.com>
>
> Â Â Â Â Â Â Â Â * config/arm/arm_cmse.h (cmse_nonsecure_caller): Add
> warn_unused_result attribute.
> Â Â Â Â Â Â Â Â (cmse_check_address_range): Add warn_unused_result attribute.
>
> libgcc/ChangeLog:
>
> 2019-07-10 Joel Hutton <Joel.Hutton@arm.com>
>
> Â Â Â Â Â Â Â Â * config/arm/cmse.c (cmse_check_address_range): Add
> warn_unused_result attribute.
>
> 2019-07-10 Joel Hutton <Joel.Hutton@arm.com>
>
> Â Â Â Â Â Â Â Â * gcc.target/arm/cmse/cmse-17.c: New test.
Thanks for the patch. Approved and applied on your behalf as r273924.
For the future, it would help speed up review to CC the relevant
maintainers on your patch submissions. You can find them in the
MAINTAINERS file in the source tree.
Thanks,
Kyrill
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-31 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 11:33 [Arm][CMSE]Add warn_unused_return attribute to cmse functions Joel Hutton
2019-07-31 8:58 ` Kyrill Tkachov
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).