From 235a98e371dca0901690b9b9644c2beb0447bf99 Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Wed, 6 Oct 2021 20:07:15 +0300 Subject: [PATCH] ARC: MWDT: enable back BUILD_ASSERT macro BUILD_ASSERT macro was disabled for MWDT toolchain from the moment of adding MWDT support to Zephyr. Built-in _Static_assert is now working fine for the most of the cases with MWDT toolchain so we can use it in BUILD_ASSERT. The only exception is _ARCH_MEM_PARTITION_ALIGN_CHECK macro as it often used with variable addresses as parameters which need to be checked at compile time. We disable _ARCH_MEM_PARTITION_ALIGN_CHECK for MWDT toolchain so we can use BUILD_ASSERT in other places. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- include/arch/arc/arch.h | 7 +++++++ include/toolchain/mwdt.h | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/arch/arc/arch.h b/include/arch/arc/arch.h index 5eed07aef53..b3fa24a504f 100644 --- a/include/arch/arc/arch.h +++ b/include/arch/arc/arch.h @@ -279,6 +279,12 @@ BUILD_ASSERT(CONFIG_PRIVILEGED_STACK_SIZE % Z_ARC_MPU_ALIGN == 0, #define K_MEM_PARTITION_IS_EXECUTABLE(attr) \ ((attr) & (AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE)) +/* + * BUILD_ASSERT in case of MWDT is a bit more picky in performing compile-time check. + * For example it can't evaluate variable address at build time like GCC toolchain can do. + * That's why we don't provide _ARCH_MEM_PARTITION_ALIGN_CHECK for MWDT toolchain. + */ +#ifndef __CCAC__ #if CONFIG_ARC_MPU_VER == 2 #define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \ BUILD_ASSERT(!(((size) & ((size) - 1))) && (size) >= Z_ARC_MPU_ALIGN \ @@ -295,6 +301,7 @@ BUILD_ASSERT(CONFIG_PRIVILEGED_STACK_SIZE % Z_ARC_MPU_ALIGN == 0, " and greater than or equal to 32." \ "start address of the partition must align with 32.") #endif +#endif /* __CCAC__ */ #endif /* CONFIG_ARC_MPU*/ /* Typedef for the k_mem_partition attribute*/ diff --git a/include/toolchain/mwdt.h b/include/toolchain/mwdt.h index 9aeb4d1b69f..5a1719e8ec2 100644 --- a/include/toolchain/mwdt.h +++ b/include/toolchain/mwdt.h @@ -84,13 +84,12 @@ #include -/* Metaware toolchain has _Static_assert. However it not able to calculate - * conditional expression in build time for some realy complex cases. ARC GNU - * toolchain works fine in this cases, so it looks like MWDT bug. So, disable - * BUILD_ASSERT macro until we fix that issue in MWDT toolchain. - */ #undef BUILD_ASSERT -#define BUILD_ASSERT(EXPR, MSG...) +#ifdef __cplusplus +#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG) +#else +#define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG) +#endif #define __builtin_arc_nop() _nop()