[llvm] Revert "[ExceptionDemo] Correct and update example ExceptionDemo" (PR #92257)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 05:55:58 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 89873694654a635cabdd861ddebd61a041d8342f 57ac757310a6283e2a9cb8fdd01af3bc4535c055 -- llvm/examples/ExceptionDemo/ExceptionDemo.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
index 0afc6b30d1..afc97c1305 100644
--- a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -141,7 +141,7 @@ static llvm::ConstantInt *ourExceptionThrownState;
 static llvm::ConstantInt *ourExceptionCaughtState;
 
 typedef std::vector<std::string> ArgNames;
-typedef std::vector<llvm::Type*> ArgTypes;
+typedef std::vector<llvm::Type *> ArgTypes;
 
 //
 // Code Generation Utilities
@@ -892,13 +892,10 @@ void generateStringPrint(llvm::LLVMContext &context,
 ///        generated, and is used to hold the constant string. A value of
 ///        false indicates that the constant string will be stored on the
 ///        stack.
-void generateIntegerPrint(llvm::LLVMContext &context,
-                          llvm::Module &module,
+void generateIntegerPrint(llvm::LLVMContext &context, llvm::Module &module,
                           llvm::IRBuilder<> &builder,
-                          llvm::Function &printFunct,
-                          llvm::Value &toPrint,
-                          std::string format,
-                          bool useGlobal = true) {
+                          llvm::Function &printFunct, llvm::Value &toPrint,
+                          std::string format, bool useGlobal = true) {
   llvm::Constant *stringConstant =
     llvm::ConstantDataArray::getString(context, format);
   llvm::Value *stringVar;
@@ -923,7 +920,6 @@ void generateIntegerPrint(llvm::LLVMContext &context,
   builder.CreateCall(&printFunct, {&toPrint, cast});
 }
 
-
 /// Generates code to handle finally block type semantics: always runs
 /// regardless of whether a thrown exception is passing through or the
 /// parent function is simply exiting. In addition to printing some state
@@ -997,10 +993,8 @@ static llvm::BasicBlock *createFinallyBlock(llvm::LLVMContext &context,
                       bufferToPrint.str(),
                       USE_GLOBAL_STR_CONSTS);
 
-  llvm::SwitchInst *theSwitch = builder.CreateSwitch(builder.CreateLoad(
-                                                       *exceptionCaughtFlag),
-                                                     &terminatorBlock,
-                                                     2);
+  llvm::SwitchInst *theSwitch = builder.CreateSwitch(
+      builder.CreateLoad(*exceptionCaughtFlag), &terminatorBlock, 2);
   theSwitch->addCase(ourExceptionCaughtState, &terminatorBlock);
   theSwitch->addCase(ourExceptionThrownState, &unwindResumeBlock);
 
@@ -1185,8 +1179,7 @@ static llvm::Function *createCatchWrappedInvokeFunction(
   llvm::Function *deleteOurException = module.getFunction("deleteOurException");
 
   // Note: function handles NULL exceptions
-  builder.CreateCall(deleteOurException,
-                     builder.CreateLoad(exceptionStorage));
+  builder.CreateCall(deleteOurException, builder.CreateLoad(exceptionStorage));
   builder.CreateRetVoid();
 
   // Normal Block
@@ -1278,9 +1271,8 @@ static llvm::Function *createCatchWrappedInvokeFunction(
   //
   // Note: ourBaseFromUnwindOffset is usually negative
   llvm::Value *typeInfoThrown = builder.CreatePointerCast(
-                                  builder.CreateConstGEP1_64(unwindException,
-                                                       ourBaseFromUnwindOffset),
-                                  ourExceptionType->getPointerTo());
+      builder.CreateConstGEP1_64(unwindException, ourBaseFromUnwindOffset),
+      ourExceptionType->getPointerTo());
 
   // Retrieve thrown exception type info type
   //
@@ -1291,15 +1283,11 @@ static llvm::Function *createCatchWrappedInvokeFunction(
   llvm::Value *typeInfoThrownType =
       builder.CreateStructGEP(builder.getPtrTy(), typeInfoThrown, 0);
 
-  generateIntegerPrint(context,
-                       module,
-                       builder,
-                       *toPrint32Int,
+  generateIntegerPrint(context, module, builder, *toPrint32Int,
                        *(builder.CreateLoad(typeInfoThrownType)),
                        "Gen: Exception type <%d> received (stack unwound) "
                        " in " +
-                       ourId +
-                       ".\n",
+                           ourId + ".\n",
                        USE_GLOBAL_STR_CONSTS);
 
   // Route to matched type info catch block or run cleanup finally block
@@ -1311,9 +1299,9 @@ static llvm::Function *createCatchWrappedInvokeFunction(
 
   for (unsigned i = 1; i <= numExceptionsToCatch; ++i) {
     nextTypeToCatch = i - 1;
-    switchToCatchBlock->addCase(llvm::ConstantInt::get(
-                                   llvm::Type::getInt32Ty(context), i),
-                                catchBlocks[nextTypeToCatch]);
+    switchToCatchBlock->addCase(
+        llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), i),
+        catchBlocks[nextTypeToCatch]);
   }
 
   llvm::verifyFunction(*ret);
@@ -1387,14 +1375,9 @@ createThrowExceptionFunction(llvm::Module &module, llvm::IRBuilder<> &builder,
   builder.SetInsertPoint(entryBlock);
 
   llvm::Function *toPrint32Int = module.getFunction("print32Int");
-  generateIntegerPrint(context,
-                       module,
-                       builder,
-                       *toPrint32Int,
-                       *exceptionType,
-                       "\nGen: About to throw exception type <%d> in " +
-                       ourId +
-                       ".\n",
+  generateIntegerPrint(context, module, builder, *toPrint32Int, *exceptionType,
+                       "\nGen: About to throw exception type <%d> in " + ourId +
+                           ".\n",
                        USE_GLOBAL_STR_CONSTS);
 
   // Switches on runtime type info type value to determine whether or not
@@ -1546,15 +1529,13 @@ typedef void (*OurExceptionThrowFunctType) (int32_t typeToThrow);
 /// @param function generated test function to run
 /// @param typeToThrow type info type of generated exception to throw, or
 ///        indicator to cause foreign exception to be thrown.
-static
-void runExceptionThrow(llvm::ExecutionEngine *engine,
-                       llvm::Function *function,
-                       int32_t typeToThrow) {
+static void runExceptionThrow(llvm::ExecutionEngine *engine,
+                              llvm::Function *function, int32_t typeToThrow) {
 
   // Find test's function pointer
   OurExceptionThrowFunctType functPtr =
-    reinterpret_cast<OurExceptionThrowFunctType>(
-       reinterpret_cast<intptr_t>(engine->getPointerToFunction(function)));
+      reinterpret_cast<OurExceptionThrowFunctType>(
+          reinterpret_cast<intptr_t>(engine->getPointerToFunction(function)));
 
   try {
     // Run test
@@ -1583,7 +1564,7 @@ void runExceptionThrow(llvm::ExecutionEngine *engine,
 // End test functions
 //
 
-typedef llvm::ArrayRef<llvm::Type*> TypeArray;
+typedef llvm::ArrayRef<llvm::Type *> TypeArray;
 
 /// This initialization routine creates type info globals and
 /// adds external function declarations to module.
@@ -1907,7 +1888,8 @@ int main(int argc, char *argv[]) {
       std::make_unique<llvm::Module>("my cool jit", Context);
   llvm::Module *module = Owner.get();
 
-  std::unique_ptr<llvm::RTDyldMemoryManager> MemMgr(new llvm::SectionMemoryManager());
+  std::unique_ptr<llvm::RTDyldMemoryManager> MemMgr(
+      new llvm::SectionMemoryManager());
 
   // Build engine with JIT
   llvm::EngineBuilder factory(std::move(Owner));
@@ -1951,11 +1933,8 @@ int main(int argc, char *argv[]) {
 
     // Generate test code using function throwCppException(...) as
     // the function which throws foreign exceptions.
-    llvm::Function *toRun =
-    createUnwindExceptionTest(*module,
-                              theBuilder,
-                              fpm,
-                              "throwCppException");
+    llvm::Function *toRun = createUnwindExceptionTest(*module, theBuilder, fpm,
+                                                      "throwCppException");
 
     executionEngine->finalizeObject();
 
@@ -1972,9 +1951,8 @@ int main(int argc, char *argv[]) {
     for (int i = 1; i < argc; ++i) {
       // Run test for each argument whose value is the exception
       // type to throw.
-      runExceptionThrow(executionEngine,
-                        toRun,
-                        (unsigned) strtoul(argv[i], NULL, 10));
+      runExceptionThrow(executionEngine, toRun,
+                        (unsigned)strtoul(argv[i], NULL, 10));
     }
 
     fprintf(stderr, "\nEnd Test:\n\n");

``````````

</details>


https://github.com/llvm/llvm-project/pull/92257


More information about the llvm-commits mailing list