[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)
commitf0efd92502a0eb33c8f8f9e1ea03b25a714b2d72
tree07a1f2d0cb396e93b11d345531d37071cc7a521b
parentce52e0ffb4f1ea7bd4fb99aea5dda75d260e438f
[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  <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