regression 1010: Clang: prevent unwanted optimization
Calling a NULL function pointer is undefined behavior in C, therefore
when the compiler identifies such a pattern it is allowed to do pretty
much anything. Clang simply does not take the "case 3" branch in
ta_entry_bad_mem_access().
In order to force the call, this patch uses a volatile function pointer
so that the compiler cannot assume anything about its value.
Signed-off-by: Jerome Forissier <jerome@forissier.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c
index 29c6814..7087789 100644
--- a/ta/os_test/os_test.c
+++ b/ta/os_test/os_test.c
@@ -895,6 +895,7 @@
{
long int stack = 0;
long int stack_addr = (long int)&stack;
+ void (*volatile null_fn_ptr)(void) = NULL;
if (param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, 0, 0, 0) &&
param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT,
@@ -909,7 +910,7 @@
*((uint32_t *)(stack_addr + 0x40000000)) = 0;
break;
case 3:
- ((void (*)(void))0) ();
+ null_fn_ptr();
break;
case 4:
((void (*)(void))(stack_addr + 0x40000000)) ();