fix(lib): clang-tidy macro parentheses warnings
This patch encloses macro arguments in parentheses, as advised by the
clang-tidy bugprone-macro-parentheses check.
Signed-off-by: Chuyue Luo <Chuyue.Luo@arm.com>
Change-Id: Ie064f565d2bd52d324630c3469d2ee272324944a
diff --git a/lib/arch/include/fake_host/instr_helpers.h b/lib/arch/include/fake_host/instr_helpers.h
index 50cf362..28cd5b5 100644
--- a/lib/arch/include/fake_host/instr_helpers.h
+++ b/lib/arch/include/fake_host/instr_helpers.h
@@ -50,7 +50,7 @@
#define DEFINE_SYSOP_FUNC(_op) \
static inline void (_op)(void) \
{ \
- (void)_op; \
+ (void)(_op); \
}
/* Define function for system instruction with register parameter */
diff --git a/lib/arch/include/simd.h b/lib/arch/include/simd.h
index c3c7a02..5b821ab 100644
--- a/lib/arch/include/simd.h
+++ b/lib/arch/include/simd.h
@@ -30,9 +30,9 @@
#define SVE_P_REG_NUM U(16)
#define SVE_FFR_REG_NUM U(1)
-#define SVE_Z_REGS_SIZE(vq) ((vq + 1) * (SVE_Z_REG_MIN_SIZE * SVE_Z_REG_NUM))
-#define SVE_P_REGS_SIZE(vq) ((vq + 1) * (SVE_P_REG_MIN_SIZE * SVE_P_REG_NUM))
-#define SVE_FFR_REGS_SIZE(vq) ((vq + 1) * (SVE_FFR_REG_MIN_SIZE * \
+#define SVE_Z_REGS_SIZE(vq) (((vq) + 1) * (SVE_Z_REG_MIN_SIZE * SVE_Z_REG_NUM))
+#define SVE_P_REGS_SIZE(vq) (((vq) + 1) * (SVE_P_REG_MIN_SIZE * SVE_P_REG_NUM))
+#define SVE_FFR_REGS_SIZE(vq) (((vq) + 1) * (SVE_FFR_REG_MIN_SIZE * \
SVE_FFR_REG_NUM))
/* SVE vq architecture limit */
diff --git a/lib/common/include/aarch64/import_sym.h b/lib/common/include/aarch64/import_sym.h
index 49b84a2..b96e6ff 100644
--- a/lib/common/include/aarch64/import_sym.h
+++ b/lib/common/include/aarch64/import_sym.h
@@ -11,7 +11,7 @@
* type
*/
#define IMPORT_SYM(type, sym, name) \
- extern unsigned long sym;\
- static const __attribute__((unused)) type name = (type) (void *)(&sym)
+ extern unsigned long (sym);\
+ static const __attribute__((unused)) type name = (type) (void *)(&(sym))
#endif /* IMPORT_SYM_H */
diff --git a/lib/common/include/utils_def.h b/lib/common/include/utils_def.h
index 5569675..353c088 100644
--- a/lib/common/include/utils_def.h
+++ b/lib/common/include/utils_def.h
@@ -69,14 +69,14 @@
(sizeof(a) / sizeof((a)[0]))
#define ARRAY_LEN(_a) \
- ((sizeof(_a) / sizeof(_a[0])) + CHECK_TYPE_IS_ARRAY(_a))
+ ((sizeof(_a) / sizeof((_a)[0])) + CHECK_TYPE_IS_ARRAY(_a))
/*
* Macro checks types of array and variable/value to write
* and reports compilation error if they mismatch.
*/
#define CHECK_ARRAY_TYPE(_a, _v) \
- _Static_assert(__builtin_types_compatible_p(typeof(_a[0]), typeof(_v)), \
+ _Static_assert(__builtin_types_compatible_p(typeof((_a)[0]), typeof(_v)), \
"array type mismatch")
/*
@@ -88,19 +88,19 @@
#define SAFE_ARRAY_READ(_a, _i, _v) \
({ \
CHECK_ARRAY_TYPE(_a, _v); \
- if (_i >= ARRAY_SIZE(_a)) { \
+ if ((_i) >= ARRAY_SIZE(_a)) { \
panic(); \
} \
- _v = _a[_i]; \
+ (_v) = (_a)[_i]; \
})
#define SAFE_ARRAY_WRITE(_a, _i, _v) \
({ \
CHECK_ARRAY_TYPE(_a, _v); \
- if (_i >= ARRAY_SIZE(_a)) { \
+ if ((_i) >= ARRAY_SIZE(_a)) { \
panic(); \
} \
- _a[_i] = _v; \
+ (_a)[_i] = (_v); \
})
#define COMPILER_ASSERT(_condition) \
@@ -120,7 +120,7 @@
#define CHECK_TYPE_IS_ARRAY(_v) \
COMPILER_ASSERT_ZERO(!__builtin_types_compatible_p(typeof(_v), \
- typeof(&(_v[0]))))
+ typeof(&((_v)[0]))))
#define IS_POWER_OF_TWO(x) \
((((x) + UL(0)) & ((x) - UL(1))) == UL(0))
@@ -132,9 +132,9 @@
#define GRANULE_ALIGNED(_addr) ALIGNED((void *)(_addr), GRANULE_SIZE)
#define ALIGNED_TO_ARRAY(_addr, _array) \
- (((uintptr_t)_addr >= (uintptr_t)&_array[0]) && \
- ((((uintptr_t)_addr - (uintptr_t)&_array[0]) % \
- sizeof(_array[0])) == UL(0)))
+ (((uintptr_t)(_addr) >= (uintptr_t)&(_array)[0]) && \
+ ((((uintptr_t)(_addr) - (uintptr_t)&(_array)[0]) % \
+ sizeof((_array)[0])) == UL(0)))
#define GRANULE_SIZE (UL(1) << GRANULE_SHIFT)
#define GRANULE_MASK (~(GRANULE_SIZE - 1U))
diff --git a/lib/xlat/include/xlat_defs.h b/lib/xlat/include/xlat_defs.h
index 1a45998..79b782e 100644
--- a/lib/xlat/include/xlat_defs.h
+++ b/lib/xlat/include/xlat_defs.h
@@ -47,7 +47,7 @@
* and it does not make any sanity check on `_level`.
*/
#define XLAT_GET_TABLE_ENTRIES(_level) \
- ((_level == XLAT_TABLE_LEVEL_MIN) ? \
+ (((_level) == XLAT_TABLE_LEVEL_MIN) ? \
XLAT_LM1_TABLE_ENTRIES : XLAT_TABLE_ENTRIES)
/*
@@ -56,7 +56,7 @@
* and it does not make any sanity check on `_level`.
*/
#define XLAT_GET_TABLE_ENTRIES_MASK(_level) \
- ((_level == XLAT_TABLE_LEVEL_MIN) ? \
+ (((_level) == XLAT_TABLE_LEVEL_MIN) ? \
XLAT_LM1_TABLE_ENTRIES_MASK : XLAT_TABLE_ENTRIES_MASK)
/* Values to convert a memory address to an index into a translation table */
diff --git a/lib/xlat/src/xlat_defs_private.h b/lib/xlat/src/xlat_defs_private.h
index 2d155e3..22833e7 100644
--- a/lib/xlat/src/xlat_defs_private.h
+++ b/lib/xlat/src/xlat_defs_private.h
@@ -89,7 +89,7 @@
#define ATTR_DEVICE MAIR_DEV_NGNRE
/* Normal Memory, Outer Write-Back non-transient, Inner Write-Back non-transient */
#define ATTR_IWBWA_OWBWA_NTR MAKE_MAIR_NORMAL_MEMORY(MAIR_NORM_WB_NTR_RWA, MAIR_NORM_WB_NTR_RWA)
-#define MAIR_ATTR_SET(attr, index) ((attr) << (index << UL(3)))
+#define MAIR_ATTR_SET(attr, index) ((attr) << ((index) << UL(3)))
#define ATTR_INDEX_MASK U(0x3)
#define ATTR_INDEX_GET(attr) (((attr) >> UL(2)) & ATTR_INDEX_MASK)
diff --git a/lib/xlat/tests/xlat_test_helpers.h b/lib/xlat/tests/xlat_test_helpers.h
index 63f8222..069ffa6 100644
--- a/lib/xlat/tests/xlat_test_helpers.h
+++ b/lib/xlat/tests/xlat_test_helpers.h
@@ -46,11 +46,11 @@
* Compare two xlat_mmap_region structures
*/
#define XLAT_TEST_XLAT_MMAP_REGION_CMP(_a, _b) \
- ((_a.base_pa == _b.base_pa) && \
- (_a.base_va == _b.base_va) && \
- (_a.size == _b.size) && \
- (_a.attr == _b.attr) && \
- (_a.granularity == _b.granularity))
+ (((_a).base_pa == (_b).base_pa) && \
+ ((_a).base_va == (_b).base_va) && \
+ ((_a).size == (_b).size) && \
+ ((_a).attr == (_b).attr) && \
+ ((_a).granularity == (_b).granularity))
/*
* Helper function to initialize a xlat_ctx_tbls structure with