Fix clang-tidy warnings in art.
* Add parentheses around macro parameters, or
use NOLINT to suppress warning.
Bug: 28705665
Test: build with WITH_TIDY=1
Change-Id: Ifc922c2e66215772042bac372754ea70074f0053
diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc
index 449f514..d5f1663 100644
--- a/compiler/elf_writer_test.cc
+++ b/compiler/elf_writer_test.cc
@@ -38,16 +38,16 @@
#define EXPECT_ELF_FILE_ADDRESS(ef, expected_value, symbol_name, build_map) \
do { \
- void* addr = reinterpret_cast<void*>(ef->FindSymbolAddress(SHT_DYNSYM, \
- symbol_name, \
- build_map)); \
+ void* addr = reinterpret_cast<void*>((ef)->FindSymbolAddress(SHT_DYNSYM, \
+ symbol_name, \
+ build_map)); \
EXPECT_NE(nullptr, addr); \
EXPECT_LT(static_cast<uintptr_t>(ART_BASE_ADDRESS), reinterpret_cast<uintptr_t>(addr)); \
- if (expected_value == nullptr) { \
- expected_value = addr; \
+ if ((expected_value) == nullptr) { \
+ (expected_value) = addr; \
} \
EXPECT_EQ(expected_value, addr); \
- EXPECT_EQ(expected_value, ef->FindDynamicSymbolAddress(symbol_name)); \
+ EXPECT_EQ(expected_value, (ef)->FindDynamicSymbolAddress(symbol_name)); \
} while (false)
TEST_F(ElfWriterTest, dlsym) {
diff --git a/compiler/linker/arm64/relative_patcher_arm64_test.cc b/compiler/linker/arm64/relative_patcher_arm64_test.cc
index 573de73..9932c79 100644
--- a/compiler/linker/arm64/relative_patcher_arm64_test.cc
+++ b/compiler/linker/arm64/relative_patcher_arm64_test.cc
@@ -701,7 +701,7 @@
#define DEFAULT_LDUR_LDR_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, DexCacheReference ## adrp_offset ## Ldur ## disp) { \
- bool has_thunk = (adrp_offset == 0xff8u || adrp_offset == 0xffcu); \
+ bool has_thunk = ((adrp_offset) == 0xff8u || (adrp_offset) == 0xffcu); \
TestAdrpLdurLdr(adrp_offset, has_thunk, 0x12345678u, disp); \
}
@@ -725,8 +725,8 @@
// LDR <Xt>, <label> is aligned when offset + displacement is a multiple of 8.
#define LDRX_PCREL_LDR_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, DexCacheReference ## adrp_offset ## XPcRel ## disp) { \
- bool unaligned = !IsAligned<8u>(adrp_offset + 4u + static_cast<uint32_t>(disp)); \
- bool has_thunk = (adrp_offset == 0xff8u || adrp_offset == 0xffcu) && unaligned; \
+ bool unaligned = !IsAligned<8u>((adrp_offset) + 4u + static_cast<uint32_t>(disp)); \
+ bool has_thunk = ((adrp_offset) == 0xff8u || (adrp_offset) == 0xffcu) && unaligned; \
TestAdrpLdrPcRelLdr(kLdrXPcRelInsn, disp, adrp_offset, has_thunk, 0x12345678u, 0x1234u); \
}
@@ -735,21 +735,21 @@
// LDR <Wt>, [SP, #<pimm>] and LDR <Xt>, [SP, #<pimm>] are always aligned. No fixup needed.
#define LDRW_SPREL_LDR_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, DexCacheReference ## adrp_offset ## WSpRel ## disp) { \
- TestAdrpLdrSpRelLdr(kLdrWSpRelInsn, disp >> 2, adrp_offset, false, 0x12345678u, 0x1234u); \
+ TestAdrpLdrSpRelLdr(kLdrWSpRelInsn, (disp) >> 2, adrp_offset, false, 0x12345678u, 0x1234u); \
}
TEST_FOR_OFFSETS(LDRW_SPREL_LDR_TEST, 0, 4)
#define LDRX_SPREL_LDR_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, DexCacheReference ## adrp_offset ## XSpRel ## disp) { \
- TestAdrpLdrSpRelLdr(kLdrXSpRelInsn, disp >> 3, adrp_offset, false, 0x12345678u, 0x1234u); \
+ TestAdrpLdrSpRelLdr(kLdrXSpRelInsn, (disp) >> 3, adrp_offset, false, 0x12345678u, 0x1234u); \
}
TEST_FOR_OFFSETS(LDRX_SPREL_LDR_TEST, 0, 8)
#define DEFAULT_LDUR_ADD_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, StringReference ## adrp_offset ## Ldur ## disp) { \
- bool has_thunk = (adrp_offset == 0xff8u || adrp_offset == 0xffcu); \
+ bool has_thunk = ((adrp_offset) == 0xff8u || (adrp_offset) == 0xffcu); \
TestAdrpLdurAdd(adrp_offset, has_thunk, disp); \
}
@@ -793,7 +793,7 @@
TEST_F(Arm64RelativePatcherTestDefault, StringReference ## adrp_offset ## AddsX0X2 ## disp) { \
/* ADDS that does not use the result of "ADRP x0, addr" but overwrites that register. */ \
uint32_t adds = kAddsXInsn | (100 << 10) | (2u << 5) | 0u; /* ADDS x0, x2, #100 */ \
- bool has_thunk = (adrp_offset == 0xff8u || adrp_offset == 0xffcu); \
+ bool has_thunk = ((adrp_offset) == 0xff8u || (adrp_offset) == 0xffcu); \
TestAdrpInsn2Add(adds, adrp_offset, has_thunk, disp); \
}
@@ -810,8 +810,8 @@
// LDR <Xt>, <label> is aligned when offset + displacement is a multiple of 8.
#define LDRX_PCREL_ADD_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, StringReference ## adrp_offset ## XPcRel ## disp) { \
- bool unaligned = !IsAligned<8u>(adrp_offset + 4u + static_cast<uint32_t>(disp)); \
- bool has_thunk = (adrp_offset == 0xff8u || adrp_offset == 0xffcu) && unaligned; \
+ bool unaligned = !IsAligned<8u>((adrp_offset) + 4u + static_cast<uint32_t>(disp)); \
+ bool has_thunk = ((adrp_offset) == 0xff8u || (adrp_offset) == 0xffcu) && unaligned; \
TestAdrpLdrPcRelAdd(kLdrXPcRelInsn, disp, adrp_offset, has_thunk, 0x12345678u); \
}
@@ -820,14 +820,14 @@
// LDR <Wt>, [SP, #<pimm>] and LDR <Xt>, [SP, #<pimm>] are always aligned. No fixup needed.
#define LDRW_SPREL_ADD_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, StringReference ## adrp_offset ## WSpRel ## disp) { \
- TestAdrpLdrSpRelAdd(kLdrWSpRelInsn, disp >> 2, adrp_offset, false, 0x12345678u); \
+ TestAdrpLdrSpRelAdd(kLdrWSpRelInsn, (disp) >> 2, adrp_offset, false, 0x12345678u); \
}
TEST_FOR_OFFSETS(LDRW_SPREL_ADD_TEST, 0, 4)
#define LDRX_SPREL_ADD_TEST(adrp_offset, disp) \
TEST_F(Arm64RelativePatcherTestDefault, StringReference ## adrp_offset ## XSpRel ## disp) { \
- TestAdrpLdrSpRelAdd(kLdrXSpRelInsn, disp >> 3, adrp_offset, false, 0x12345678u); \
+ TestAdrpLdrSpRelAdd(kLdrXSpRelInsn, (disp) >> 3, adrp_offset, false, 0x12345678u); \
}
TEST_FOR_OFFSETS(LDRX_SPREL_ADD_TEST, 0, 8)
diff --git a/compiler/utils/intrusive_forward_list_test.cc b/compiler/utils/intrusive_forward_list_test.cc
index 517142e..f2efa4d 100644
--- a/compiler/utils/intrusive_forward_list_test.cc
+++ b/compiler/utils/intrusive_forward_list_test.cc
@@ -39,12 +39,12 @@
return lhs.value < rhs.value;
}
-#define ASSERT_LISTS_EQUAL(expected, value) \
- do { \
- ASSERT_EQ(expected.empty(), value.empty()); \
- ASSERT_EQ(std::distance(expected.begin(), expected.end()), \
- std::distance(value.begin(), value.end())); \
- ASSERT_TRUE(std::equal(expected.begin(), expected.end(), value.begin())); \
+#define ASSERT_LISTS_EQUAL(expected, value) \
+ do { \
+ ASSERT_EQ((expected).empty(), (value).empty()); \
+ ASSERT_EQ(std::distance((expected).begin(), (expected).end()), \
+ std::distance((value).begin(), (value).end())); \
+ ASSERT_TRUE(std::equal((expected).begin(), (expected).end(), (value).begin())); \
} while (false)
TEST(IntrusiveForwardList, IteratorToConstIterator) {
diff --git a/runtime/entrypoints_order_test.cc b/runtime/entrypoints_order_test.cc
index 004cdc4..b102334 100644
--- a/runtime/entrypoints_order_test.cc
+++ b/runtime/entrypoints_order_test.cc
@@ -37,7 +37,7 @@
// name.
#define EXPECT_OFFSET_DIFF(first_type, first_field, second_type, second_field, diff, name) \
CHECKED(OFFSETOF_MEMBER(second_type, second_field) \
- - OFFSETOF_MEMBER(first_type, first_field) == diff, name)
+ - OFFSETOF_MEMBER(first_type, first_field) == (diff), name)
// Helper macro for when the fields are from the same type.
#define EXPECT_OFFSET_DIFFNP(type, first_field, second_field, diff) \
@@ -45,15 +45,16 @@
type ## _ ## first_field ## _ ## second_field)
// Helper macro for when the fields are from the same type and in the same member of said type.
+// NOLINT, do not add parentheses around 'prefix'.
#define EXPECT_OFFSET_DIFFP(type, prefix, first_field, second_field, diff) \
- EXPECT_OFFSET_DIFF(type, prefix . first_field, type, prefix . second_field, diff, \
+ EXPECT_OFFSET_DIFF(type, prefix . first_field, type, prefix . second_field, diff, /* NOLINT */ \
type ## _ ## prefix ## _ ## first_field ## _ ## second_field)
// Macro to check whether two fields have at least an expected difference in offsets. The error is
// named name.
#define EXPECT_OFFSET_DIFF_GT(first_type, first_field, second_type, second_field, diff, name) \
CHECKED(OFFSETOF_MEMBER(second_type, second_field) \
- - OFFSETOF_MEMBER(first_type, first_field) >= diff, name)
+ - OFFSETOF_MEMBER(first_type, first_field) >= (diff), name)
// Helper macro for when the fields are from the same type.
#define EXPECT_OFFSET_DIFF_GT3(type, first_field, second_field, diff, name) \
diff --git a/runtime/gc/space/space_test.h b/runtime/gc/space/space_test.h
index 20ef44a..23e937d 100644
--- a/runtime/gc/space/space_test.h
+++ b/runtime/gc/space/space_test.h
@@ -354,7 +354,7 @@
#define TEST_SizeFootPrintGrowthLimitAndTrimRandom(name, spaceName, spaceFn, size) \
TEST_F(spaceName##RandomTest, SizeFootPrintGrowthLimitAndTrim_RandomAllocationsWithMax_##name) { \
- SizeFootPrintGrowthLimitAndTrimDriver(-size, spaceFn); \
+ SizeFootPrintGrowthLimitAndTrimDriver(-(size), spaceFn); \
}
#define TEST_SPACE_CREATE_FN_STATIC(spaceName, spaceFn) \
diff --git a/runtime/instrumentation_test.cc b/runtime/instrumentation_test.cc
index 684c471..2cc35cf 100644
--- a/runtime/instrumentation_test.cc
+++ b/runtime/instrumentation_test.cc
@@ -588,7 +588,7 @@
do { \
Instrumentation* const instr = Runtime::Current()->GetInstrumentation(); \
bool interpreter = \
- (_level == Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); \
+ ((_level) == Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); \
EXPECT_EQ(_level, GetCurrentInstrumentationLevel()); \
EXPECT_EQ(_user_count, GetInstrumentationUserCount()); \
if (instr->IsForcedInterpretOnly()) { \
diff --git a/runtime/jni_internal_test.cc b/runtime/jni_internal_test.cc
index 6495474..fe0081c 100644
--- a/runtime/jni_internal_test.cc
+++ b/runtime/jni_internal_test.cc
@@ -1105,8 +1105,9 @@
ExpectException(aioobe_); \
\
/* Prepare a couple of buffers. */ \
- std::unique_ptr<scalar_type[]> src_buf(new scalar_type[size]); \
- std::unique_ptr<scalar_type[]> dst_buf(new scalar_type[size]); \
+ /* NOLINT, no parentheses around scalar_type. */ \
+ std::unique_ptr<scalar_type[]> src_buf(new scalar_type[size]); /* NOLINT */ \
+ std::unique_ptr<scalar_type[]> dst_buf(new scalar_type[size]); /* NOLINT */ \
for (jsize i = 0; i < size; ++i) { src_buf[i] = scalar_type(i); } \
for (jsize i = 0; i < size; ++i) { dst_buf[i] = scalar_type(-1); } \
\
@@ -1131,7 +1132,7 @@
<< "GetPrimitiveArrayCritical not equal"; \
env_->ReleasePrimitiveArrayCritical(a, v, 0); \
/* GetXArrayElements */ \
- scalar_type* xs = env_->get_elements_fn(a, nullptr); \
+ scalar_type* xs = env_->get_elements_fn(a, nullptr); /* NOLINT, scalar_type */ \
EXPECT_EQ(memcmp(&src_buf[0], xs, size * sizeof(scalar_type)), 0) \
<< # get_elements_fn " not equal"; \
env_->release_elements_fn(a, xs, 0); \
diff --git a/test/901-hello-ti-agent/basics.cc b/test/901-hello-ti-agent/basics.cc
index 81a1b66..3a475c6 100644
--- a/test/901-hello-ti-agent/basics.cc
+++ b/test/901-hello-ti-agent/basics.cc
@@ -35,7 +35,7 @@
#define CHECK_CALL_SUCCESS(c) \
do { \
- if (c != JNI_OK) { \
+ if ((c) != JNI_OK) { \
printf("call " #c " did not succeed\n"); \
return -1; \
} \