[llvm-branch-commits] [llvm-gcc-branch] r99675 - /llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp

Bill Wendling isanbard at gmail.com
Fri Mar 26 16:43:47 PDT 2010


Author: void
Date: Fri Mar 26 18:43:47 2010
New Revision: 99675

URL: http://llvm.org/viewvc/llvm-project?rev=99675&view=rev
Log:
$ svn merge -c 99670 https://llvm.org/svn/llvm-project/llvm-gcc-4.2/trunk
--- Merging r99670 into '.':
U    gcc/llvm-convert.cpp


Modified:
    llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp?rev=99675&r1=99674&r2=99675&view=diff
==============================================================================
--- llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Morbo/gcc/llvm-convert.cpp Fri Mar 26 18:43:47 2010
@@ -2089,6 +2089,9 @@
     // Add selections for each handler.
     foreach_reachable_handler(i, false, AddHandler, &Handlers);
 
+    bool HasCleanup = false;
+    static Value *CatchAll = 0;
+
     for (std::vector<struct eh_region *>::iterator I = Handlers.begin(),
          E = Handlers.end(); I != E; ++I) {
       struct eh_region *region = *I;
@@ -2115,9 +2118,16 @@
 
         if (!TypeList) {
           // Catch-all - push a null pointer.
-          Args.push_back(
-            Constant::getNullValue(Type::getInt8PtrTy(Context))
-          );
+          if (!CatchAll) {
+            Constant *Init =
+              Constant::getNullValue(Type::getInt8PtrTy(Context));
+
+            CatchAll = new GlobalVariable(*TheModule, Init->getType(), true,
+                                          GlobalVariable::LinkOnceAnyLinkage,
+                                          Init, ".llvm.eh.catch.all.value");
+          }
+
+          Args.push_back(CatchAll);
         } else {
           // Add the type infos.
           for (; TypeList; TypeList = TREE_CHAIN(TypeList)) {
@@ -2125,30 +2135,43 @@
             Args.push_back(Emit(TType, 0));
           }
         }
+      } else {
+        // Cleanup.
+        HasCleanup = true;
       }
     }
 
     if (can_throw_external_1(i, false)) {
-      // Some exceptions from this region may not be caught by any handler.
-      // Since invokes are required to branch to the unwind label no matter
-      // what exception is being unwound, append a catch-all.
-
-      // The representation of a catch-all is language specific.
-      Value *CatchAll;
-      if (USING_SJLJ_EXCEPTIONS || !lang_eh_catch_all) {
-        // Use a "cleanup" - this should be good enough for most languages.
-        CatchAll = ConstantInt::get(Type::getInt32Ty(Context), 0);
+      if (HasCleanup && Args.size() == 2) {
+        Args.push_back(ConstantInt::get(Type::getInt32Ty(Context), 0));
       } else {
-        tree catch_all_type = lang_eh_catch_all();
-        if (catch_all_type == NULL_TREE)
-          // Use a C++ style null catch-all object.
-          CatchAll = Constant::getNullValue(
-                                    Type::getInt8PtrTy(Context));
-        else
-          // This language has a type that catches all others.
-          CatchAll = Emit(catch_all_type, 0);
+        // Some exceptions from this region may not be caught by any handler.
+        // Since invokes are required to branch to the unwind label no matter
+        // what exception is being unwound, append a catch-all.
+
+        // The representation of a catch-all is language specific.
+        if (USING_SJLJ_EXCEPTIONS || !lang_eh_catch_all) {
+          // Use a "cleanup" - this should be good enough for most languages.
+          Args.push_back(ConstantInt::get(Type::getInt32Ty(Context), 0));
+        } else {
+          if (!CatchAll) {
+            Constant *Init = 0;
+            tree catch_all_type = lang_eh_catch_all();
+            if (catch_all_type == NULL_TREE)
+              // Use a C++ style null catch-all object.
+              Init = Constant::getNullValue(Type::getInt8PtrTy(Context));
+            else
+              // This language has a type that catches all others.
+              Init = cast<Constant>(Emit(catch_all_type, 0));
+
+            CatchAll = new GlobalVariable(*TheModule, Init->getType(), true,
+                                          GlobalVariable::PrivateLinkage,
+                                          Init, ".llvm.eh.catch.all.value");
+          }
+
+          Args.push_back(CatchAll);
+        }
       }
-      Args.push_back(CatchAll);
     }
 
     // Emit the selector call.





More information about the llvm-branch-commits mailing list