[ARM] Fix PR85203: cmse_nonsecure_caller returns wrong result
commit08661f80efc229dd6d89a0754a44c7fe425d3e88
authorthopre01 <thopre01@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Apr 2018 17:31:46 +0000 (4 17:31 +0000)
committerthopre01 <thopre01@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Apr 2018 17:31:46 +0000 (4 17:31 +0000)
treee9e5adf2d4f7c429d7e3c97af13680720a9c12f7
parent53d4dec13135eb2d2e43bac735951c697bf87f63
[ARM] Fix PR85203: cmse_nonsecure_caller returns wrong result

__builtin_cmse_nonsecure_caller implementation returns true in almost
all cases due to 2 separate bugs:

* gen_addsi is used instead of gen_andsi to retrieve the lsb
* the lsb boolean value is not negated but the specification says
  the intrinsic should return true for a nonsecure caller and a
  nonsecure caller is characterized with LR's lsb being 0

This was not caught due to (1) lack of runtime test and (2) the existing
RTL scan not taking into account that '.' matches newline in Tcl regular
expressions.

This commit fixes the implementation issues and improves testing of
cmse_nonsecure_caller by (1) adding a runtime test for the secure caller
case and (2) looking for an SET insn of an AND expression in the right
function. This leaves the nonsecure caller case only partly tested
since the exact value being AND and the negation are not covered by the
scan and the existing test infrastructure does not allow 2 separate
compilation and link to be performed. It is enough though to catch the
current incorrect behavior.

The commit also reorganize the scan directives in cmse-1.c to more
easily identify what function they are intended to test in the file.

2018-04-04  Thomas Preud'homme  <thomas.preudhomme@arm.com>

gcc/
    PR target/85203
    * config/arm/arm-builtins.c (arm_expand_builtin): Change
    expansion to perform a bitwise AND of the argument followed by a
    boolean negation of the result.

gcc/testsuite/
    PR target/85203
    * gcc.target/arm/cmse/cmse-1.c: Tighten cmse_nonsecure_caller RTL scan
    to match a single insn of the baz function.  Move scan directives at
    the end of the file below the functions they are trying to test for
    better readability.
    * gcc.target/arm/cmse/cmse-16.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259097 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/config/arm/arm-builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/cmse/cmse-1.c
gcc/testsuite/gcc.target/arm/cmse/cmse-16.c [new file with mode: 0644]