CodeGen: ensure that the runtime calling convention matches

Incorrect specification of the calling convention results in UB which can cause
the code path to be eliminated.  Simplify the existing code by using the
RuntimeCall constructor in `CodeGenFunction`.

llvm-svn: 284154
diff --git a/clang/lib/CodeGen/CGObjCRuntime.cpp b/clang/lib/CodeGen/CGObjCRuntime.cpp
index ebc8292..3da7ed2 100644
--- a/clang/lib/CodeGen/CGObjCRuntime.cpp
+++ b/clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -150,18 +150,16 @@
   };
 
   struct CallObjCEndCatch final : EHScopeStack::Cleanup {
-    CallObjCEndCatch(bool MightThrow, llvm::Value *Fn) :
-      MightThrow(MightThrow), Fn(Fn) {}
+    CallObjCEndCatch(bool MightThrow, llvm::Value *Fn)
+        : MightThrow(MightThrow), Fn(Fn) {}
     bool MightThrow;
     llvm::Value *Fn;
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      if (!MightThrow) {
-        CGF.Builder.CreateCall(Fn)->setDoesNotThrow();
-        return;
-      }
-
-      CGF.EmitRuntimeCallOrInvoke(Fn);
+      if (MightThrow)
+        CGF.EmitRuntimeCallOrInvoke(Fn);
+      else
+        CGF.EmitNounwindRuntimeCall(Fn);
     }
   };
 }
@@ -230,10 +228,8 @@
 
     // Enter the catch.
     llvm::Value *Exn = RawExn;
-    if (beginCatchFn) {
-      Exn = CGF.Builder.CreateCall(beginCatchFn, RawExn, "exn.adjusted");
-      cast<llvm::CallInst>(Exn)->setDoesNotThrow();
-    }
+    if (beginCatchFn)
+      Exn = CGF.EmitNounwindRuntimeCall(beginCatchFn, RawExn, "exn.adjusted");
 
     CodeGenFunction::LexicalScope cleanups(CGF, Handler.Body->getSourceRange());