Make sure to emit the catch parameter as well as the catch body.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56101 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index a3da594..73f9489 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -456,4 +456,12 @@
   CGM.getObjCRuntime().EmitThrowStmt(*this, S);
 }
 
+void CodeGenFunction::EmitObjCAtCatchStmt(const ObjCAtCatchStmt &S)
+{
+  if (const Stmt *CatchParam = S.getCatchParamStmt())
+    EmitStmt(CatchParam);
+  
+  EmitStmt(S.getCatchBody());
+}
+
 CGObjCRuntime::~CGObjCRuntime() {}
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 0134c70..d1875ac 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -1459,8 +1459,9 @@
           MatchesAll = true;
       }
       
-      if (MatchesAll) {        
-        CGF.EmitStmt(CatchStmt->getCatchBody());
+      if (MatchesAll) {   
+        CGF.EmitStmt(CatchStmt);
+        
         CGF.Builder.CreateBr(FinallyBlock);
         
         CGF.EmitBlock(NextCatchBlock);        
@@ -1485,7 +1486,7 @@
       
       // Emit the @catch block.
       CGF.EmitBlock(MatchedBlock);
-      CGF.EmitStmt(CatchStmt->getCatchBody());
+      CGF.EmitStmt(CatchStmt);
       CGF.Builder.CreateBr(FinallyBlock);
       
       CGF.EmitBlock(NextCatchBlock);
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index bf3469e..5b88a19 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -81,8 +81,8 @@
     EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));
     break;    
   case Stmt::ObjCAtCatchStmtClass:
-    assert(0 && "@catch statements should be handled by EmitObjCAtTryStmt");
-    break;
+    EmitObjCAtCatchStmt(cast<ObjCAtCatchStmt>(*S));
+    break;    
   case Stmt::ObjCAtFinallyStmtClass:
     assert(0 && "@finally statements should be handled by EmitObjCAtTryStmt");
     break;
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 263a0f2..e2b0a2b 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -269,6 +269,7 @@
   
   void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
   void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
+  void EmitObjCAtCatchStmt(const ObjCAtCatchStmt &S);
   void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
   
   //===--------------------------------------------------------------------===//