]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Arm][CMSE]Add warn_unused_return attribute to cmse functions
authorJoel Hutton <Joel.Hutton@arm.com>
Wed, 31 Jul 2019 08:56:35 +0000 (08:56 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Wed, 31 Jul 2019 08:56:35 +0000 (08:56 +0000)
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-31  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-31  Joel Hutton  <Joel.Hutton@arm.com>

         * config/arm/cmse.c (cmse_check_address_range): Add
warn_unused_result attribute.

2019-07-31  Joel Hutton  <Joel.Hutton@arm.com>

         * gcc.target/arm/cmse/cmse-17.c: New test.

From-SVN: r273924

gcc/ChangeLog
gcc/config/arm/arm_cmse.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/cmse/cmse-17.c [new file with mode: 0644]
libgcc/ChangeLog
libgcc/config/arm/cmse.c

index 6c3fb2ca9e8fce42a1997d323a652af63c2f944e..af3089a8a55a116a8a3215b62baa28bdca6c2c60 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-31  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.
+
 2019-07-31  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/91257
index b543cbfe455ae57487be199f7c918eb87db30bf2..a72c46f1a954bd3ba4aefcdbb7a31085d0f583c0 100644 (file)
@@ -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) \
index 26100368a8d599cea6cec2ac431c586a3b7d483d..3d44853383c0a32b3d1c4e1b31dbabab6c3ad853 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-31  Joel Hutton  <Joel.Hutton@arm.com>
+
+       * gcc.target/arm/cmse/cmse-17.c: New test.
+
 2019-07-30  Martin Sebor  <msebor@redhat.com>
 
        PR testsuite/91258
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 (file)
index 0000000..a2cce09
--- /dev/null
@@ -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" } */
+}
index 7997ad871f468ca2f48f6f5135b1fd77fe0b84a4..c9aea1dde159b00e35072fd09f9609315b17e856 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-31  Joel Hutton  <Joel.Hutton@arm.com>
+
+       * config/arm/cmse.c (cmse_check_address_range): Add
+       warn_unused_result attribute.
+
 2019-07-22  Martin Liska  <mliska@suse.cz>
 
        * config/pa/stublib.c: Remove stub symbol __gnu_lto_v1.
index 34a46fde2d2fcd9dc181bf5a74dd698de2ebc9bd..0c5a3eaefab49ae07e67b82481fdd0d8dd100227 100644 (file)
@@ -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;