| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-mcmse -fshort-enums" } */ |
| 3 |
/* { dg-final { check-function-bodies "**" "" "" } } */ |
| 4 |
|
| 5 |
#include <arm_cmse.h> |
| 6 |
#include <stdbool.h> |
| 7 |
|
| 8 |
#define ARRAY_SIZE (256) |
| 9 |
char array[ARRAY_SIZE]; |
| 10 |
|
| 11 |
enum offset |
| 12 |
{ |
| 13 |
zero = 0, |
| 14 |
one = 1, |
| 15 |
two = 2 |
| 16 |
}; |
| 17 |
|
| 18 |
/* |
| 19 |
**__acle_se_unsignSecureFunc: |
| 20 |
** ... |
| 21 |
** uxtb r0, r0 |
| 22 |
** ... |
| 23 |
*/ |
| 24 |
__attribute__((cmse_nonsecure_entry)) char unsignSecureFunc (unsigned char index) { |
| 25 |
if (index >= ARRAY_SIZE) |
| 26 |
return 0; |
| 27 |
return array[index]; |
| 28 |
} |
| 29 |
|
| 30 |
/* |
| 31 |
**__acle_se_signSecureFunc: |
| 32 |
** ... |
| 33 |
** sxtb r0, r0 |
| 34 |
** ... |
| 35 |
*/ |
| 36 |
__attribute__((cmse_nonsecure_entry)) char signSecureFunc (signed char index) { |
| 37 |
if (index >= ARRAY_SIZE) |
| 38 |
return 0; |
| 39 |
return array[index]; |
| 40 |
} |
| 41 |
|
| 42 |
/* |
| 43 |
**__acle_se_shortUnsignSecureFunc: |
| 44 |
** ... |
| 45 |
** uxth r0, r0 |
| 46 |
** ... |
| 47 |
*/ |
| 48 |
__attribute__((cmse_nonsecure_entry)) char shortUnsignSecureFunc (unsigned short index) { |
| 49 |
if (index >= ARRAY_SIZE) |
| 50 |
return 0; |
| 51 |
return array[index]; |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
**__acle_se_shortSignSecureFunc: |
| 56 |
** ... |
| 57 |
** sxth r0, r0 |
| 58 |
** ... |
| 59 |
*/ |
| 60 |
__attribute__((cmse_nonsecure_entry)) char shortSignSecureFunc (signed short index) { |
| 61 |
if (index >= ARRAY_SIZE) |
| 62 |
return 0; |
| 63 |
return array[index]; |
| 64 |
} |
| 65 |
|
| 66 |
/* |
| 67 |
**__acle_se_enumSecureFunc: |
| 68 |
** ... |
| 69 |
** uxtb r0, r0 |
| 70 |
** ... |
| 71 |
*/ |
| 72 |
__attribute__((cmse_nonsecure_entry)) char enumSecureFunc (enum offset index) { |
| 73 |
|
| 74 |
// Compiler may optimize away bounds check as value is an unsigned char. |
| 75 |
|
| 76 |
// According to AAPCS caller will zero extend to ensure value is < 256. |
| 77 |
|
| 78 |
if (index >= ARRAY_SIZE) |
| 79 |
return 0; |
| 80 |
return array[index]; |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
**__acle_se_boolSecureFunc: |
| 85 |
** ... |
| 86 |
** uxtb r0, r0 |
| 87 |
** ... |
| 88 |
*/ |
| 89 |
__attribute__((cmse_nonsecure_entry)) char boolSecureFunc (bool index) { |
| 90 |
if (index >= ARRAY_SIZE) |
| 91 |
return 0; |
| 92 |
return array[index]; |
| 93 |
} |
| 94 |
|
| 95 |
/* |
| 96 |
**__acle_se_boolCharShortEnumSecureFunc: |
| 97 |
** ... |
| 98 |
** uxtb r0, r0 |
| 99 |
** uxtb r1, r1 |
| 100 |
** uxth r2, r2 |
| 101 |
** uxtb r3, r3 |
| 102 |
** ... |
| 103 |
*/ |
| 104 |
__attribute__((cmse_nonsecure_entry,optimize(0))) char boolCharShortEnumSecureFunc (bool a, unsigned char b, unsigned short c, enum offset d) { |
| 105 |
size_t index = a + b + c + d; |
| 106 |
if (index >= ARRAY_SIZE) |
| 107 |
return 0; |
| 108 |
return array[index]; |
| 109 |
} |