[llvm] Wrap multi-statement macro definitions with do ... while (0)

This commit is contained in:
owenca 2022-07-16 20:57:44 -07:00
parent 3a6b766b1b
commit cd434a202c
2 changed files with 53 additions and 45 deletions

View File

@ -51,44 +51,48 @@ static cl::opt<std::string>
cl::cat(LLVMReduceOptions)); cl::cat(LLVMReduceOptions));
#define DELTA_PASSES \ #define DELTA_PASSES \
DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass) \ do { \
DELTA_PASS("aliases", reduceAliasesDeltaPass) \ DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass) \
DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass) \ DELTA_PASS("aliases", reduceAliasesDeltaPass) \
DELTA_PASS("functions", reduceFunctionsDeltaPass) \ DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass) \
DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) \ DELTA_PASS("functions", reduceFunctionsDeltaPass) \
DELTA_PASS("global-values", reduceGlobalValuesDeltaPass) \ DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) \
DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) \ DELTA_PASS("global-values", reduceGlobalValuesDeltaPass) \
DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass) \ DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) \
DELTA_PASS("global-variables", reduceGlobalsDeltaPass) \ DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass) \
DELTA_PASS("metadata", reduceMetadataDeltaPass) \ DELTA_PASS("global-variables", reduceGlobalsDeltaPass) \
DELTA_PASS("arguments", reduceArgumentsDeltaPass) \ DELTA_PASS("metadata", reduceMetadataDeltaPass) \
DELTA_PASS("instructions", reduceInstructionsDeltaPass) \ DELTA_PASS("arguments", reduceArgumentsDeltaPass) \
DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass) \ DELTA_PASS("instructions", reduceInstructionsDeltaPass) \
DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass) \ DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass) \
DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) \ DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass) \
DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) \ DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) \
DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass) \ DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) \
DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \ DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass) \
DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \ DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \
DELTA_PASS("attributes", reduceAttributesDeltaPass) \ DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \
DELTA_PASS("module-data", reduceModuleDataDeltaPass) DELTA_PASS("attributes", reduceAttributesDeltaPass) \
DELTA_PASS("module-data", reduceModuleDataDeltaPass) \
} while (false)
#define DELTA_PASSES_MIR \ #define DELTA_PASSES_MIR \
DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass) \ do { \
DELTA_PASS("ir-instruction-references", \ DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass) \
reduceIRInstructionReferencesDeltaPass) \ DELTA_PASS("ir-instruction-references", \
DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass) \ reduceIRInstructionReferencesDeltaPass) \
DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass) \ DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass) \
DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass) \ DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass) \
DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass) \ DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass) \
DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass) DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass) \
DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass) \
} while (false)
static void runAllDeltaPasses(TestRunner &Tester) { static void runAllDeltaPasses(TestRunner &Tester) {
#define DELTA_PASS(NAME, FUNC) FUNC(Tester); #define DELTA_PASS(NAME, FUNC) FUNC(Tester);
if (Tester.getProgram().isMIR()) { if (Tester.getProgram().isMIR()) {
DELTA_PASSES_MIR DELTA_PASSES_MIR;
} else { } else {
DELTA_PASSES DELTA_PASSES;
} }
#undef DELTA_PASS #undef DELTA_PASS
} }
@ -100,9 +104,9 @@ static void runDeltaPassName(TestRunner &Tester, StringRef PassName) {
return; \ return; \
} }
if (Tester.getProgram().isMIR()) { if (Tester.getProgram().isMIR()) {
DELTA_PASSES_MIR DELTA_PASSES_MIR;
} else { } else {
DELTA_PASSES DELTA_PASSES;
} }
#undef DELTA_PASS #undef DELTA_PASS
errs() << "unknown pass \"" << PassName << "\"\n"; errs() << "unknown pass \"" << PassName << "\"\n";
@ -113,9 +117,9 @@ void llvm::printDeltaPasses(raw_ostream &OS) {
OS << "Delta passes (pass to `--delta-passes=` as a comma separated list):\n"; OS << "Delta passes (pass to `--delta-passes=` as a comma separated list):\n";
#define DELTA_PASS(NAME, FUNC) OS << " " << NAME << "\n"; #define DELTA_PASS(NAME, FUNC) OS << " " << NAME << "\n";
OS << " IR:\n"; OS << " IR:\n";
DELTA_PASSES DELTA_PASSES;
OS << " MIR:\n"; OS << " MIR:\n";
DELTA_PASSES_MIR DELTA_PASSES_MIR;
#undef DELTA_PASS #undef DELTA_PASS
} }

View File

@ -16,18 +16,22 @@ using namespace llvm;
namespace { namespace {
#define EXPECT_VTY_EQ(LHS, RHS) \ #define EXPECT_VTY_EQ(LHS, RHS) \
ASSERT_NE(LHS, nullptr) << #LHS << " must not be null"; \ do { \
ASSERT_NE(RHS, nullptr) << #RHS << " must not be null"; \ ASSERT_NE(LHS, nullptr) << #LHS << " must not be null"; \
EXPECT_EQ(LHS, RHS) << "Expect that " << #LHS << " == " << #RHS << " where " \ ASSERT_NE(RHS, nullptr) << #RHS << " must not be null"; \
<< #LHS << " = " << *LHS << " and " << #RHS << " = " \ EXPECT_EQ(LHS, RHS) << "Expect that " << #LHS << " == " << #RHS \
<< *RHS; << " where " << #LHS << " = " << *LHS << " and " \
<< #RHS << " = " << *RHS; \
} while (false)
#define EXPECT_VTY_NE(LHS, RHS) \ #define EXPECT_VTY_NE(LHS, RHS) \
ASSERT_NE(LHS, nullptr) << #LHS << " must not be null"; \ do { \
ASSERT_NE(RHS, nullptr) << #RHS << " must not be null"; \ ASSERT_NE(LHS, nullptr) << #LHS << " must not be null"; \
EXPECT_NE(LHS, RHS) << "Expect that " << #LHS << " != " << #RHS << " where " \ ASSERT_NE(RHS, nullptr) << #RHS << " must not be null"; \
<< #LHS << " = " << *LHS << " and " << #RHS << " = " \ EXPECT_NE(LHS, RHS) << "Expect that " << #LHS << " != " << #RHS \
<< *RHS; << " where " << #LHS << " = " << *LHS << " and " \
<< #RHS << " = " << *RHS; \
} while (false)
TEST(VectorTypesTest, FixedLength) { TEST(VectorTypesTest, FixedLength) {
LLVMContext Ctx; LLVMContext Ctx;