Improve catch parameter bindings for scalar non-pointers.  WIP.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90492 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
index 1ceb254..93bdf8c 100644
--- a/lib/CodeGen/CGException.cpp
+++ b/lib/CodeGen/CGException.cpp
@@ -170,12 +170,13 @@
 // CopyObject - Utility to copy an object.  Calls copy constructor as necessary.
 // N is casted to the right type.
 static void CopyObject(CodeGenFunction &CGF, QualType ObjectType,
-                       llvm::Value *E, llvm::Value *N) {
+                       bool WasPointer, llvm::Value *E, llvm::Value *N) {
   // Store the throw exception in the exception object.
   if (!CGF.hasAggregateLLVMType(ObjectType)) {
     llvm::Value *Value = E;
+    if (!WasPointer)
+      Value = CGF.Builder.CreateLoad(Value);
     const llvm::Type *ValuePtrTy = Value->getType()->getPointerTo(0);
-    
     CGF.Builder.CreateStore(Value, CGF.Builder.CreateBitCast(N, ValuePtrTy));
   } else {
     const llvm::Type *Ty = CGF.ConvertType(ObjectType)->getPointerTo(0);
@@ -382,8 +383,11 @@
       if (CatchParam) {
         QualType CatchType = CatchParam->getType().getNonReferenceType();
         setInvokeDest(TerminateHandler);
-        if (!CatchType.getTypePtr()->isPointerType())
+        bool WasPointer = true;
+        if (!CatchType.getTypePtr()->isPointerType()) {
+          WasPointer = false;
           CatchType = getContext().getPointerType(CatchType);
+        }
         ExcObject = Builder.CreateBitCast(ExcObject, ConvertType(CatchType));
         EmitLocalBlockVarDecl(*CatchParam);
 #if 0
@@ -394,7 +398,7 @@
         // cleanup doesn't start until after the ctor completes, use a decl
         // init?
         CopyObject(*this, CatchParam->getType().getNonReferenceType(),
-                   ExcObject, GetAddrOfLocalVar(CatchParam));
+                   WasPointer, ExcObject, GetAddrOfLocalVar(CatchParam));
 #endif
         setInvokeDest(MatchHandler);
       }