From: Joel Hutton Date: Wed, 31 Jul 2019 08:56:35 +0000 (+0000) Subject: [Arm][CMSE]Add warn_unused_return attribute to cmse functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f0efd92502a0eb33c8f8f9e1ea03b25a714b2d72;p=gcc.git [Arm][CMSE]Add warn_unused_return attribute to cmse functions 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 * 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 * config/arm/cmse.c (cmse_check_address_range): Add warn_unused_result attribute. 2019-07-31 Joel Hutton * gcc.target/arm/cmse/cmse-17.c: New test. From-SVN: r273924 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6c3fb2ca9e8..af3089a8a55 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-07-31 Joel Hutton + + * 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 PR tree-optimization/91257 diff --git a/gcc/config/arm/arm_cmse.h b/gcc/config/arm/arm_cmse.h index b543cbfe455..a72c46f1a95 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/ChangeLog b/gcc/testsuite/ChangeLog index 26100368a8d..3d44853383c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-31 Joel Hutton + + * gcc.target/arm/cmse/cmse-17.c: New test. + 2019-07-30 Martin Sebor 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 index 00000000000..a2cce09afae --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-17.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmse"} */ + +#include + +void foo() +{ + int *data; + cmse_check_address_range((int*)data, 0, 0); /* { dg-warning "ignoring return value" } */ +} diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index 7997ad871f4..c9aea1dde15 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,8 @@ +2019-07-31 Joel Hutton + + * config/arm/cmse.c (cmse_check_address_range): Add + warn_unused_result attribute. + 2019-07-22 Martin Liska * config/pa/stublib.c: Remove stub symbol __gnu_lto_v1. diff --git a/libgcc/config/arm/cmse.c b/libgcc/config/arm/cmse.c index 34a46fde2d2..0c5a3eaefab 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;