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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 16 20:58:29 PDT 2022


Author: owenca
Date: 2022-07-16T20:58:20-07:00
New Revision: cd434a202c227c485fb83e84d44bfba09b0febb3

URL: https://github.com/llvm/llvm-project/commit/cd434a202c227c485fb83e84d44bfba09b0febb3
DIFF: https://github.com/llvm/llvm-project/commit/cd434a202c227c485fb83e84d44bfba09b0febb3.diff

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

Added: 
    

Modified: 
    llvm/tools/llvm-reduce/DeltaManager.cpp
    llvm/unittests/IR/VectorTypesTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index 49dd8f1c8a87c..98fd818bb0459 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -51,44 +51,48 @@ static cl::opt<std::string>
                 cl::cat(LLVMReduceOptions));
 
 #define DELTA_PASSES                                                           \
-  DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass)                 \
-  DELTA_PASS("aliases", reduceAliasesDeltaPass)                                \
-  DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass)                 \
-  DELTA_PASS("functions", reduceFunctionsDeltaPass)                            \
-  DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass)                       \
-  DELTA_PASS("global-values", reduceGlobalValuesDeltaPass)                     \
-  DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass)                   \
-  DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass)        \
-  DELTA_PASS("global-variables", reduceGlobalsDeltaPass)                       \
-  DELTA_PASS("metadata", reduceMetadataDeltaPass)                              \
-  DELTA_PASS("arguments", reduceArgumentsDeltaPass)                            \
-  DELTA_PASS("instructions", reduceInstructionsDeltaPass)                      \
-  DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass)           \
-  DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass)                     \
-  DELTA_PASS("operands-one", reduceOperandsOneDeltaPass)                       \
-  DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass)                       \
-  DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass)                \
-  DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass)                     \
-  DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)                  \
-  DELTA_PASS("attributes", reduceAttributesDeltaPass)                          \
-  DELTA_PASS("module-data", reduceModuleDataDeltaPass)
+  do {                                                                         \
+    DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass)               \
+    DELTA_PASS("aliases", reduceAliasesDeltaPass)                              \
+    DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass)               \
+    DELTA_PASS("functions", reduceFunctionsDeltaPass)                          \
+    DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass)                     \
+    DELTA_PASS("global-values", reduceGlobalValuesDeltaPass)                   \
+    DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass)                 \
+    DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass)      \
+    DELTA_PASS("global-variables", reduceGlobalsDeltaPass)                     \
+    DELTA_PASS("metadata", reduceMetadataDeltaPass)                            \
+    DELTA_PASS("arguments", reduceArgumentsDeltaPass)                          \
+    DELTA_PASS("instructions", reduceInstructionsDeltaPass)                    \
+    DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass)         \
+    DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass)                   \
+    DELTA_PASS("operands-one", reduceOperandsOneDeltaPass)                     \
+    DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass)                     \
+    DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass)              \
+    DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass)                   \
+    DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)                \
+    DELTA_PASS("attributes", reduceAttributesDeltaPass)                        \
+    DELTA_PASS("module-data", reduceModuleDataDeltaPass)                       \
+  } while (false)
 
 #define DELTA_PASSES_MIR                                                       \
-  DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass)                   \
-  DELTA_PASS("ir-instruction-references",                                      \
-             reduceIRInstructionReferencesDeltaPass)                           \
-  DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass)          \
-  DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass)    \
-  DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)          \
-  DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass)                  \
-  DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass)
+  do {                                                                         \
+    DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass)                 \
+    DELTA_PASS("ir-instruction-references",                                    \
+               reduceIRInstructionReferencesDeltaPass)                         \
+    DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass)        \
+    DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass)  \
+    DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)        \
+    DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass)                \
+    DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass)          \
+  } while (false)
 
 static void runAllDeltaPasses(TestRunner &Tester) {
 #define DELTA_PASS(NAME, FUNC) FUNC(Tester);
   if (Tester.getProgram().isMIR()) {
-    DELTA_PASSES_MIR
+    DELTA_PASSES_MIR;
   } else {
-    DELTA_PASSES
+    DELTA_PASSES;
   }
 #undef DELTA_PASS
 }
@@ -100,9 +104,9 @@ static void runDeltaPassName(TestRunner &Tester, StringRef PassName) {
     return;                                                                    \
   }
   if (Tester.getProgram().isMIR()) {
-    DELTA_PASSES_MIR
+    DELTA_PASSES_MIR;
   } else {
-    DELTA_PASSES
+    DELTA_PASSES;
   }
 #undef DELTA_PASS
   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";
 #define DELTA_PASS(NAME, FUNC) OS << "  " << NAME << "\n";
   OS << " IR:\n";
-  DELTA_PASSES
+  DELTA_PASSES;
   OS << " MIR:\n";
-  DELTA_PASSES_MIR
+  DELTA_PASSES_MIR;
 #undef DELTA_PASS
 }
 

diff  --git a/llvm/unittests/IR/VectorTypesTest.cpp b/llvm/unittests/IR/VectorTypesTest.cpp
index c8a09808428fa..af0f29f45d7aa 100644
--- a/llvm/unittests/IR/VectorTypesTest.cpp
+++ b/llvm/unittests/IR/VectorTypesTest.cpp
@@ -16,18 +16,22 @@ using namespace llvm;
 namespace {
 
 #define EXPECT_VTY_EQ(LHS, RHS)                                                \
-  ASSERT_NE(LHS, nullptr) << #LHS << " must not be null";                      \
-  ASSERT_NE(RHS, nullptr) << #RHS << " must not be null";                      \
-  EXPECT_EQ(LHS, RHS) << "Expect that " << #LHS << " == " << #RHS << " where " \
-                      << #LHS << " = " << *LHS << " and " << #RHS << " = "     \
-                      << *RHS;
+  do {                                                                         \
+    ASSERT_NE(LHS, nullptr) << #LHS << " must not be null";                    \
+    ASSERT_NE(RHS, nullptr) << #RHS << " must not be null";                    \
+    EXPECT_EQ(LHS, RHS) << "Expect that " << #LHS << " == " << #RHS            \
+                        << " where " << #LHS << " = " << *LHS << " and "       \
+                        << #RHS << " = " << *RHS;                              \
+  } while (false)
 
 #define EXPECT_VTY_NE(LHS, RHS)                                                \
-  ASSERT_NE(LHS, nullptr) << #LHS << " must not be null";                      \
-  ASSERT_NE(RHS, nullptr) << #RHS << " must not be null";                      \
-  EXPECT_NE(LHS, RHS) << "Expect that " << #LHS << " != " << #RHS << " where " \
-                      << #LHS << " = " << *LHS << " and " << #RHS << " = "     \
-                      << *RHS;
+  do {                                                                         \
+    ASSERT_NE(LHS, nullptr) << #LHS << " must not be null";                    \
+    ASSERT_NE(RHS, nullptr) << #RHS << " must not be null";                    \
+    EXPECT_NE(LHS, RHS) << "Expect that " << #LHS << " != " << #RHS            \
+                        << " where " << #LHS << " = " << *LHS << " and "       \
+                        << #RHS << " = " << *RHS;                              \
+  } while (false)
 
 TEST(VectorTypesTest, FixedLength) {
   LLVMContext Ctx;


        


More information about the llvm-commits mailing list