Patch to fix 32-bit @try failure with internal assertion when compiling 
an Objective-C rethrow nested inside another try/catch block. (fixes radar 7466728).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91335 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index d847cea..fb920f0 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -2541,8 +2541,11 @@
   // through finally.
   CGF.PushCleanupBlock(FinallyBlock);
 
-  CGF.ObjCEHValueStack.push_back(0);
-
+  if (CGF.ObjCEHValueStack.empty())
+    CGF.ObjCEHValueStack.push_back(0);
+  // If This is a nested @try, caught exception is that of enclosing @try.
+  else
+    CGF.ObjCEHValueStack.push_back(CGF.ObjCEHValueStack.back());
   // Allocate memory for the exception data and rethrow pointer.
   llvm::Value *ExceptionData = CGF.CreateTempAlloca(ObjCTypes.ExceptionDataTy,
                                                     "exceptiondata.ptr");
diff --git a/test/CodeGenObjC/nested-rethrow.m b/test/CodeGenObjC/nested-rethrow.m
new file mode 100644
index 0000000..187998e
--- /dev/null
+++ b/test/CodeGenObjC/nested-rethrow.m
@@ -0,0 +1,24 @@
+// RUN: clang -cc1 -triple i386-apple-darwin9 -emit-llvm %s -o - | FileCheck %s
+
+#include <stdio.h>
+
+int main()
+{
+    @try {
+        @throw @"foo";
+    } @catch (id e) {
+        @try {
+// CHECK: call void @objc_exception_throw
+           @throw;
+        } @catch (id e) {
+            if (e) {
+                printf("caught \n");
+            } else {
+                printf("caught (WRONG)\n");
+            }
+        } @catch (...) {
+            printf("caught nothing (WRONG)\n");
+        }
+    }
+}
+