Merge remote-tracking branch 'origin/swift-4.1-branch' into stable
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index cfbe763..703f588 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -2394,30 +2394,9 @@
 
   QualType mergeObjCGCQualifiers(QualType, QualType);
 
-  /// This function merges the ExtParameterInfo lists of two functions. It
-  /// returns true if the lists are compatible. The merged list is returned in
-  /// NewParamInfos.
-  ///
-  /// \param FirstFnType The type of the first function.
-  ///
-  /// \param SecondFnType The type of the second function.
-  ///
-  /// \param CanUseFirst This flag is set to true if the first function's
-  /// ExtParameterInfo list can be used as the composite list of
-  /// ExtParameterInfo.
-  ///
-  /// \param CanUseSecond This flag is set to true if the second function's
-  /// ExtParameterInfo list can be used as the composite list of
-  /// ExtParameterInfo.
-  ///
-  /// \param NewParamInfos The composite list of ExtParameterInfo. The list is
-  /// empty if none of the flags are set.
-  ///
-  bool mergeExtParameterInfo(
-      const FunctionProtoType *FirstFnType,
-      const FunctionProtoType *SecondFnType,
-      bool &CanUseFirst, bool &CanUseSecond,
-      SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &NewParamInfos);
+  bool doFunctionTypesMatchOnExtParameterInfos(
+         const FunctionProtoType *FromFunctionType,
+         const FunctionProtoType *ToFunctionType);
 
   void ResetObjCLayout(const ObjCContainerDecl *CD);
 
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h
index e5217c2..984096f 100644
--- a/include/clang/AST/Type.h
+++ b/include/clang/AST/Type.h
@@ -3152,7 +3152,6 @@
       ABIMask         = 0x0F,
       IsConsumed      = 0x10,
       HasPassObjSize  = 0x20,
-      IsNoEscape      = 0x40,
     };
     unsigned char Data;
 
@@ -3193,19 +3192,6 @@
       return Copy;
     }
 
-    bool isNoEscape() const {
-      return Data & IsNoEscape;
-    }
-
-    ExtParameterInfo withIsNoEscape(bool NoEscape) const {
-      ExtParameterInfo Copy = *this;
-      if (NoEscape)
-        Copy.Data |= IsNoEscape;
-      else
-        Copy.Data &= ~IsNoEscape;
-      return Copy;
-    }
-
     unsigned char getOpaqueValue() const { return Data; }
     static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
       ExtParameterInfo result;
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index faea449..9b4dd62 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -1390,10 +1390,10 @@
   let Documentation = [Undocumented];
 }
 
-def NoEscape : Attr {
-  let Spellings = [GNU<"noescape">, CXX11<"clang", "noescape">];
-  let Subjects = SubjectList<[ParmVar]>;
-  let Documentation = [NoEscapeDocs];
+def NoEscape : InheritableAttr {
+  let Spellings = [GCC<"noescape">];
+  let Subjects = SubjectList<[ParmVar], WarnDiag, "ExpectedParameter">;
+  let Documentation = [Undocumented];
 }
 
 def AssumeAligned : InheritableAttr {
diff --git a/include/clang/Basic/AttrDocs.td b/include/clang/Basic/AttrDocs.td
index da8cb31..f18540a 100644
--- a/include/clang/Basic/AttrDocs.td
+++ b/include/clang/Basic/AttrDocs.td
@@ -112,47 +112,6 @@
   }];
 }
 
-def NoEscapeDocs : Documentation {
-  let Category = DocCatVariable;
-  let Content = [{
-``noescape`` placed on a function parameter of a pointer type is used to inform
-the compiler that the pointer cannot escape: that is, no reference to the object
-the pointer points to that is derived from the parameter value will survive
-after the function returns. Users are responsible for making sure parameters
-annotated with ``noescape`` do not actuallly escape.
-
-For example:
-
-.. code-block:: c
-  int *gp;
-
-  void nonescapingFunc(__attribute__((noescape)) int *p) {
-    *p += 100; // OK.
-  }
-
-  void escapingFunc(__attribute__((noescape)) int *p) {
-    gp = p; // Not OK.
-  }
-
-Additionally, when the parameter is a `block pointer
-<https://clang.llvm.org/docs/BlockLanguageSpec.html>`, the same restriction
-applies to copies of the block. For example:
-
-  typedef void (^BlockTy)();
-  BlockTy g0, g1;
-
-  void nonescapingFunc(__attribute__((noescape)) BlockTy block) {
-    block(); // OK.
-  }
-
-  void escapingFunc(__attribute__((noescape)) BlockTy block) {
-    g0 = block; // Not OK.
-    g1 = Block_copy(block); // Not OK either.
-  }
-
-  }];
-}
-
 def CarriesDependencyDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td
index 8a7a003..9387ed2 100644
--- a/include/clang/Basic/DiagnosticGroups.td
+++ b/include/clang/Basic/DiagnosticGroups.td
@@ -88,7 +88,6 @@
   DiagGroup<"gnu-string-literal-operator-template">;
 def UndefinedVarTemplate : DiagGroup<"undefined-var-template">;
 def UndefinedFuncTemplate : DiagGroup<"undefined-func-template">;
-def MissingNoEscape : DiagGroup<"missing-noescape">;
 
 def DeleteIncomplete : DiagGroup<"delete-incomplete">;
 def DeleteNonVirtualDtor : DiagGroup<"delete-non-virtual-dtor">;
@@ -484,9 +483,6 @@
                                     PragmaClangAttribute]>;
 def UnknownWarningOption : DiagGroup<"unknown-warning-option">;
 def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
-def NSConsumedMismatch : DiagGroup<"nsconsumed-mismatch">;
-def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">;
-
 def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">;
 def UnknownAttributes : DiagGroup<"unknown-attributes">;
 def IgnoredAttributes : DiagGroup<"ignored-attributes">;
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 3841963..c33bf18 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1645,11 +1645,6 @@
   "virtual function %0 has different calling convention attributes "
   "%diff{($) than the function it overrides (which has calling convention $)|"
   "than the function it overrides}1,2">;
-def warn_overriding_method_missing_noescape : Warning<
-  "parameter of overriding method should be annotated with "
-  "__attribute__((noescape))">, InGroup<MissingNoEscape>;
-def note_overridden_marked_noescape : Note<
-  "parameter of overridden method is annotated with __attribute__((noescape))">;
 
 def err_covariant_return_inaccessible_base : Error<
   "invalid covariant return for virtual function: %1 is a "
@@ -8277,12 +8272,12 @@
   "feature, not permitted in C++">;
 def err_type_unsupported : Error<
   "%0 is not supported on this target">;
-def warn_nsconsumed_attribute_mismatch : Warning<
+def err_nsconsumed_attribute_mismatch : Error<
   "overriding method has mismatched ns_consumed attribute on its"
-  " parameter">, InGroup<NSConsumedMismatch>;
-def warn_nsreturns_retained_attribute_mismatch : Warning<
+  " parameter">;
+def err_nsreturns_retained_attribute_mismatch : Error<
   "overriding method has mismatched ns_returns_%select{not_retained|retained}0"
-  " attributes">, InGroup<NSReturnsMismatch>;
+  " attributes">;
 
 def err_nserrordomain_not_tagdecl : Error<
   "ns_error_domain attribute only valid on "
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 5ea823d..a7d673c 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -7957,17 +7957,9 @@
     if (lproto->getTypeQuals() != rproto->getTypeQuals())
       return QualType();
 
-    SmallVector<FunctionProtoType::ExtParameterInfo, 4> newParamInfos;
-    bool canUseLeft, canUseRight;
-    if (!mergeExtParameterInfo(lproto, rproto, canUseLeft, canUseRight,
-                               newParamInfos))
+    if (!doFunctionTypesMatchOnExtParameterInfos(rproto, lproto))
       return QualType();
 
-    if (!canUseLeft)
-      allLTypes = false;
-    if (!canUseRight)
-      allRTypes = false;
-
     // Check parameter type compatibility
     SmallVector<QualType, 10> types;
     for (unsigned i = 0, n = lproto->getNumParams(); i < n; i++) {
@@ -7998,8 +7990,6 @@
 
     FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo();
     EPI.ExtInfo = einfo;
-    EPI.ExtParameterInfos =
-        newParamInfos.empty() ? nullptr : newParamInfos.data();
     return getFunctionType(retType, types, EPI);
   }
 
@@ -8359,50 +8349,26 @@
   llvm_unreachable("Invalid Type::Class!");
 }
 
-bool ASTContext::mergeExtParameterInfo(
-    const FunctionProtoType *FirstFnType, const FunctionProtoType *SecondFnType,
-    bool &CanUseFirst, bool &CanUseSecond,
-    SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &NewParamInfos) {
-  assert(NewParamInfos.empty() && "param info list not empty");
-  CanUseFirst = CanUseSecond = true;
-  bool FirstHasInfo = FirstFnType->hasExtParameterInfos();
-  bool SecondHasInfo = SecondFnType->hasExtParameterInfos();
-
+bool ASTContext::doFunctionTypesMatchOnExtParameterInfos(
+                   const FunctionProtoType *firstFnType,
+                   const FunctionProtoType *secondFnType) {
   // Fast path: if the first type doesn't have ext parameter infos,
-  // we match if and only if the second type also doesn't have them.
-  if (!FirstHasInfo && !SecondHasInfo)
-    return true;
+  // we match if and only if they second type also doesn't have them.
+  if (!firstFnType->hasExtParameterInfos())
+    return !secondFnType->hasExtParameterInfos();
 
-  bool NeedParamInfo = false;
-  size_t E = FirstHasInfo ? FirstFnType->getExtParameterInfos().size()
-                          : SecondFnType->getExtParameterInfos().size();
+  // Otherwise, we can only match if the second type has them.
+  if (!secondFnType->hasExtParameterInfos())
+    return false;
 
-  for (size_t I = 0; I < E; ++I) {
-    FunctionProtoType::ExtParameterInfo FirstParam, SecondParam;
-    if (FirstHasInfo)
-      FirstParam = FirstFnType->getExtParameterInfo(I);
-    if (SecondHasInfo)
-      SecondParam = SecondFnType->getExtParameterInfo(I);
+  auto firstEPI = firstFnType->getExtParameterInfos();
+  auto secondEPI = secondFnType->getExtParameterInfos();
+  assert(firstEPI.size() == secondEPI.size());
 
-    // Cannot merge unless everything except the noescape flag matches.
-    if (FirstParam.withIsNoEscape(false) != SecondParam.withIsNoEscape(false))
+  for (size_t i = 0, n = firstEPI.size(); i != n; ++i) {
+    if (firstEPI[i] != secondEPI[i])
       return false;
-
-    bool FirstNoEscape = FirstParam.isNoEscape();
-    bool SecondNoEscape = SecondParam.isNoEscape();
-    bool IsNoEscape = FirstNoEscape && SecondNoEscape;
-    NewParamInfos.push_back(FirstParam.withIsNoEscape(IsNoEscape));
-    if (NewParamInfos.back().getOpaqueValue())
-      NeedParamInfo = true;
-    if (FirstNoEscape != IsNoEscape)
-      CanUseFirst = false;
-    if (SecondNoEscape != IsNoEscape)
-      CanUseSecond = false;
   }
-
-  if (!NeedParamInfo)
-    NewParamInfos.clear();
-
   return true;
 }
 
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp
index ac02785..4e7c6c4 100644
--- a/lib/AST/ItaniumMangle.cpp
+++ b/lib/AST/ItaniumMangle.cpp
@@ -2586,9 +2586,6 @@
 
   if (PI.isConsumed())
     mangleVendorQualifier("ns_consumed");
-
-  if (PI.isNoEscape())
-    mangleVendorQualifier("noescape");
 }
 
 // <type>          ::= <function-type>
diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp
index 5ebe315..269abb2 100644
--- a/lib/AST/TypePrinter.cpp
+++ b/lib/AST/TypePrinter.cpp
@@ -666,8 +666,6 @@
 
       auto EPI = T->getExtParameterInfo(i);
       if (EPI.isConsumed()) OS << "__attribute__((ns_consumed)) ";
-      if (EPI.isNoEscape())
-        OS << "__attribute__((noescape)) ";
       auto ABI = EPI.getABI();
       if (ABI != ParameterABI::Ordinary)
         OS << "__attribute__((" << getParameterABISpelling(ABI) << ")) ";
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 4f5a31e..316bf44 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -455,15 +455,11 @@
 CodeGenTypes::arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
                                               QualType receiverType) {
   SmallVector<CanQualType, 16> argTys;
-  SmallVector<FunctionProtoType::ExtParameterInfo, 4> extParamInfos(2);
   argTys.push_back(Context.getCanonicalParamType(receiverType));
   argTys.push_back(Context.getCanonicalParamType(Context.getObjCSelType()));
   // FIXME: Kill copy?
   for (const auto *I : MD->parameters()) {
     argTys.push_back(Context.getCanonicalParamType(I->getType()));
-    auto extParamInfo = FunctionProtoType::ExtParameterInfo().withIsNoEscape(
-        I->hasAttr<NoEscapeAttr>());
-    extParamInfos.push_back(extParamInfo);
   }
 
   FunctionType::ExtInfo einfo;
@@ -479,7 +475,7 @@
 
   return arrangeLLVMFunctionInfo(
       GetReturnType(MD->getReturnType()), /*instanceMethod=*/false,
-      /*chainCall=*/false, argTys, einfo, extParamInfos, required);
+      /*chainCall=*/false, argTys, einfo, {}, required);
 }
 
 const CGFunctionInfo &
@@ -2096,9 +2092,6 @@
       break;
     }
 
-    if (FI.getExtParameterInfo(ArgNo).isNoEscape())
-      Attrs.addAttribute(llvm::Attribute::NoCapture);
-
     if (Attrs.hasAttributes()) {
       unsigned FirstIRArg, NumIRArgs;
       std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index aa3921a..8249715 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -1518,19 +1518,23 @@
 }
 
 static void handleNoEscapeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (D->isInvalidDecl())
+  ParmVarDecl *PD = dyn_cast<ParmVarDecl>(D);
+  if (!PD)
     return;
 
   // noescape only applies to pointer types.
-  QualType T = cast<ParmVarDecl>(D)->getType();
-  if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_pointers_only)
-        << Attr.getName() << Attr.getRange() << 0;
+  QualType T = PD->getType();
+  if (!T->isAnyPointerType() && !T->isBlockPointerType() && 
+      !T->isReferenceType() && !T->isArrayType() && 
+      !T->isMemberPointerType()) {
+    S.Diag(Attr.getLoc(), diag::warn_attribute_noescape_non_pointer)
+      << T;
     return;
   }
 
   D->addAttr(::new (S.Context) NoEscapeAttr(
-      Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
+                                 Attr.getRange(), S.Context,
+                                 Attr.getAttributeSpellingListIndex()));
 }
 
 static void handleAssumeAlignedAttr(Sema &S, Decl *D,
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index e4e384b..081864c 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -14021,21 +14021,8 @@
 
 bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
                                              const CXXMethodDecl *Old) {
-  const auto *NewFT = New->getType()->getAs<FunctionProtoType>();
-  const auto *OldFT = Old->getType()->getAs<FunctionProtoType>();
-
-  if (OldFT->hasExtParameterInfos()) {
-    for (unsigned I = 0, E = OldFT->getNumParams(); I != E; ++I)
-      // A parameter of the overriding method should be annotated with noescape
-      // if the corresponding parameter of the overridden method is annotated.
-      if (OldFT->getExtParameterInfo(I).isNoEscape() &&
-          !NewFT->getExtParameterInfo(I).isNoEscape()) {
-        Diag(New->getParamDecl(I)->getLocation(),
-             diag::warn_overriding_method_missing_noescape);
-        Diag(Old->getParamDecl(I)->getLocation(),
-             diag::note_overridden_marked_noescape);
-      }
-  }
+  const FunctionType *NewFT = New->getType()->getAs<FunctionType>();
+  const FunctionType *OldFT = Old->getType()->getAs<FunctionType>();
 
   CallingConv NewCC = NewFT->getCallConv(), OldCC = OldFT->getCallConv();
 
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index c0a3fd1..b132381 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -158,44 +158,34 @@
            diag::note_related_result_type_overridden);
   }
   if (getLangOpts().ObjCAutoRefCount) {
-    Diags.setSeverity(diag::warn_nsreturns_retained_attribute_mismatch,
-                      diag::Severity::Error, SourceLocation());
-    Diags.setSeverity(diag::warn_nsconsumed_attribute_mismatch,
-                      diag::Severity::Error, SourceLocation());
-  }
-
-  if ((NewMethod->hasAttr<NSReturnsRetainedAttr>() !=
-       Overridden->hasAttr<NSReturnsRetainedAttr>())) {
-    Diag(NewMethod->getLocation(),
-         diag::warn_nsreturns_retained_attribute_mismatch) << 1;
-    Diag(Overridden->getLocation(), diag::note_previous_decl) << "method";
-  }
-  if ((NewMethod->hasAttr<NSReturnsNotRetainedAttr>() !=
-       Overridden->hasAttr<NSReturnsNotRetainedAttr>())) {
-    Diag(NewMethod->getLocation(),
-         diag::warn_nsreturns_retained_attribute_mismatch) << 0;
-    Diag(Overridden->getLocation(), diag::note_previous_decl)  << "method";
-  }
-
-  ObjCMethodDecl::param_const_iterator oi = Overridden->param_begin(),
-                                       oe = Overridden->param_end();
-  for (ObjCMethodDecl::param_iterator ni = NewMethod->param_begin(),
-                                      ne = NewMethod->param_end();
-       ni != ne && oi != oe; ++ni, ++oi) {
-    const ParmVarDecl *oldDecl = (*oi);
-    ParmVarDecl *newDecl = (*ni);
-    if (newDecl->hasAttr<NSConsumedAttr>() !=
-        oldDecl->hasAttr<NSConsumedAttr>()) {
-      Diag(newDecl->getLocation(), diag::warn_nsconsumed_attribute_mismatch);
-      Diag(oldDecl->getLocation(), diag::note_previous_decl) << "parameter";
+    if ((NewMethod->hasAttr<NSReturnsRetainedAttr>() !=
+         Overridden->hasAttr<NSReturnsRetainedAttr>())) {
+        Diag(NewMethod->getLocation(),
+             diag::err_nsreturns_retained_attribute_mismatch) << 1;
+        Diag(Overridden->getLocation(), diag::note_previous_decl) 
+        << "method";
     }
-
-    // A parameter of the overriding method should be annotated with noescape
-    // if the corresponding parameter of the overridden method is annotated.
-    if (oldDecl->hasAttr<NoEscapeAttr>() && !newDecl->hasAttr<NoEscapeAttr>()) {
-      Diag(newDecl->getLocation(),
-           diag::warn_overriding_method_missing_noescape);
-      Diag(oldDecl->getLocation(), diag::note_overridden_marked_noescape);
+    if ((NewMethod->hasAttr<NSReturnsNotRetainedAttr>() !=
+              Overridden->hasAttr<NSReturnsNotRetainedAttr>())) {
+        Diag(NewMethod->getLocation(),
+             diag::err_nsreturns_retained_attribute_mismatch) << 0;
+        Diag(Overridden->getLocation(), diag::note_previous_decl) 
+        << "method";
+    }
+    ObjCMethodDecl::param_const_iterator oi = Overridden->param_begin(),
+                                         oe = Overridden->param_end();
+    for (ObjCMethodDecl::param_iterator
+           ni = NewMethod->param_begin(), ne = NewMethod->param_end();
+         ni != ne && oi != oe; ++ni, ++oi) {
+      const ParmVarDecl *oldDecl = (*oi);
+      ParmVarDecl *newDecl = (*ni);
+      if (newDecl->hasAttr<NSConsumedAttr>() != 
+          oldDecl->hasAttr<NSConsumedAttr>()) {
+        Diag(newDecl->getLocation(),
+             diag::err_nsconsumed_attribute_mismatch);
+        Diag(oldDecl->getLocation(), diag::note_previous_decl) 
+          << "parameter";
+      }
     }
   }
 }
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 8f28ec2..36f24fd 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -1481,23 +1481,6 @@
                  .getTypePtr());
       Changed = true;
     }
-
-    // Convert FromFPT's ExtParameterInfo if necessary. The conversion is valid
-    // only if the ExtParameterInfo lists of the two function prototypes can be
-    // merged and the merged list is identical to ToFPT's ExtParameterInfo list.
-    SmallVector<FunctionProtoType::ExtParameterInfo, 4> NewParamInfos;
-    bool CanUseToFPT, CanUseFromFPT;
-    if (Context.mergeExtParameterInfo(ToFPT, FromFPT, CanUseToFPT,
-                                      CanUseFromFPT, NewParamInfos) &&
-        CanUseToFPT && !CanUseFromFPT) {
-      FunctionProtoType::ExtProtoInfo ExtInfo = FromFPT->getExtProtoInfo();
-      ExtInfo.ExtParameterInfos =
-          NewParamInfos.empty() ? nullptr : NewParamInfos.data();
-      QualType QT = Context.getFunctionType(FromFPT->getReturnType(),
-                                            FromFPT->getParamTypes(), ExtInfo);
-      FromFn = QT->getAs<FunctionType>();
-      Changed = true;
-    }
   }
 
   if (!Changed)
@@ -2680,12 +2663,8 @@
        // Argument types are too different. Abort.
        return false;
    }
-
-   SmallVector<FunctionProtoType::ExtParameterInfo, 4> NewParamInfos;
-   bool CanUseToFPT, CanUseFromFPT;
-   if (!Context.mergeExtParameterInfo(ToFunctionType, FromFunctionType,
-                                      CanUseToFPT, CanUseFromFPT,
-                                      NewParamInfos))
+   if (!Context.doFunctionTypesMatchOnExtParameterInfos(FromFunctionType,
+                                                        ToFunctionType))
      return false;
 
    ConvertedType = ToType;
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 6022d82..62cdb6c 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -4468,11 +4468,6 @@
             HasAnyInterestingExtParameterInfos = true;
           }
 
-          if (Param->hasAttr<NoEscapeAttr>()) {
-            ExtParameterInfos[i] = ExtParameterInfos[i].withIsNoEscape(true);
-            HasAnyInterestingExtParameterInfos = true;
-          }
-
           ParamTys.push_back(ParamTy);
         }
 
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m
index 4ac72ab..29af194 100644
--- a/test/Analysis/retain-release.m
+++ b/test/Analysis/retain-release.m
@@ -1776,15 +1776,15 @@
 
 // rdar://problem/8024350
 @protocol F18P
-- (id) clone; // expected-note 2 {{method declared here}}
+- (id) clone;
 @end
 @interface F18 : NSObject<F18P> @end
 @interface F18(Cat)
-- (id) clone NS_RETURNS_RETAINED; // expected-warning {{overriding method has mismatched ns_returns_retained attributes}}
+- (id) clone NS_RETURNS_RETAINED;
 @end
 
 @implementation F18
-- (id) clone { // expected-warning {{overriding method has mismatched ns_returns_retained attributes}}
+- (id) clone {
   return [F18 alloc];
 }
 @end
diff --git a/test/CodeGenCXX/noescape.cpp b/test/CodeGenCXX/noescape.cpp
deleted file mode 100644
index 90d24de..0000000
--- a/test/CodeGenCXX/noescape.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
-
-struct S {
-  int a[4];
-  S(int *, int * __attribute__((noescape)));
-  S &operator=(int * __attribute__((noescape)));
-  void m0(int *, int * __attribute__((noescape)));
-  virtual void vm1(int *, int * __attribute__((noescape)));
-};
-
-// CHECK: define void @_ZN1SC2EPiS0_(%struct.S* {{.*}}, {{.*}}, {{.*}} nocapture)
-// CHECK: define void @_ZN1SC1EPiS0_(%struct.S* {{.*}}, {{.*}}, {{.*}} nocapture) {{.*}} {
-// CHECK: call void @_ZN1SC2EPiS0_(%struct.S* {{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
-
-S::S(int *, int * __attribute__((noescape))) {}
-
-// CHECK: define {{.*}} %struct.S* @_ZN1SaSEPi(%struct.S* {{.*}}, {{.*}} nocapture)
-S &S::operator=(int * __attribute__((noescape))) { return *this; }
-
-// CHECK: define void @_ZN1S2m0EPiS0_(%struct.S* {{.*}}, {{.*}} nocapture)
-void S::m0(int *, int * __attribute__((noescape))) {}
-
-// CHECK: define void @_ZN1S3vm1EPiS0_(%struct.S* {{.*}}, {{.*}} nocapture)
-void S::vm1(int *, int * __attribute__((noescape))) {}
-
-// CHECK-LABEL: define void @_Z5test0P1SPiS1_(
-// CHECK: call void @_ZN1SC1EPiS0_(%struct.S* {{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
-// CHECK: call {{.*}} %struct.S* @_ZN1SaSEPi(%struct.S* {{.*}}, {{.*}} nocapture {{.*}})
-// CHECK: call void @_ZN1S2m0EPiS0_(%struct.S* {{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
-// CHECK: call void {{.*}}(%struct.S* {{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
-void test0(S *s, int *p0, int *p1) {
-  S t(p0, p1);
-  t = p1;
-  s->m0(p0, p1);
-  s->vm1(p0, p1);
-}
-
-namespace std {
-  typedef decltype(sizeof(0)) size_t;
-}
-
-// CHECK: define {{.*}} @_ZnwmPv({{.*}}, {{.*}} nocapture {{.*}})
-void *operator new(std::size_t, void * __attribute__((noescape)) p) {
-  return p;
-}
-
-// CHECK-LABEL: define i8* @_Z5test1Pv(
-// CHECK : %call = call {{.*}} @_ZnwmPv({{.*}}, {{.*}} nocapture {{.*}})
-void *test1(void *p0) {
-  return ::operator new(16, p0);
-}
-
-// CHECK-LABEL: define void @_Z5test2PiS_(
-// CHECK: call void @"_ZZ5test2PiS_ENK3$_0clES_S_"({{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
-// CHECK: define internal void @"_ZZ5test2PiS_ENK3$_0clES_S_"({{.*}}, {{.*}}, {{.*}} nocapture)
-void test2(int *p0, int *p1) {
-  auto t = [](int *, int * __attribute__((noescape))){};
-  t(p0, p1);
-}
-
-// CHECK-LABEL: define void @_Z5test3PFvU8noescapePiES_(
-// CHECK: call void {{.*}}(i32* nocapture {{.*}})
-typedef void (*NoEscapeFunc)(__attribute__((noescape)) int *);
-
-void test3(NoEscapeFunc f, int *p) {
-  f(p);
-}
diff --git a/test/CodeGenObjC/noescape.m b/test/CodeGenObjC/noescape.m
deleted file mode 100644
index 49bc0e4..0000000
--- a/test/CodeGenObjC/noescape.m
+++ /dev/null
@@ -1,71 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fblocks -emit-llvm -o - %s | FileCheck %s
-
-typedef void (^BlockTy)(void);
-
-union U {
-  int *i;
-  long long *ll;
-} __attribute__((transparent_union));
-
-void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
-void noescapeFunc1(__attribute__((noescape)) int *);
-void noescapeFunc2(__attribute__((noescape)) id);
-void noescapeFunc3(__attribute__((noescape)) union U);
-
-// CHECK-LABEL: define void @test0(
-// CHECK: call void @noescapeFunc0({{.*}}, {{.*}} nocapture {{.*}})
-// CHECK: declare void @noescapeFunc0(i8*, {{.*}} nocapture)
-void test0(BlockTy b) {
-  noescapeFunc0(0, b);
-}
-
-// CHECK-LABEL: define void @test1(
-// CHECK: call void @noescapeFunc1({{.*}} nocapture {{.*}})
-// CHECK: declare void @noescapeFunc1({{.*}} nocapture)
-void test1(int *i) {
-  noescapeFunc1(i);
-}
-
-// CHECK-LABEL: define void @test2(
-// CHECK: call void @noescapeFunc2({{.*}} nocapture {{.*}})
-// CHECK: declare void @noescapeFunc2({{.*}} nocapture)
-void test2(id i) {
-  noescapeFunc2(i);
-}
-
-// CHECK-LABEL: define void @test3(
-// CHECK: call void @noescapeFunc3({{.*}} nocapture {{.*}})
-// CHECK: declare void @noescapeFunc3({{.*}} nocapture)
-void test3(union U u) {
-  noescapeFunc3(u);
-}
-
-// CHECK: define internal void @"\01-[C0 m0:]"({{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
-
-// CHECK-LABEL: define void @test4(
-// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32*)*)(i8* {{.*}}, i8* {{.*}}, i32* nocapture {{.*}})
-
-@interface C0
--(void) m0:(int*)__attribute__((noescape)) p0;
-@end
-
-@implementation C0
--(void) m0:(int*)__attribute__((noescape)) p0 {
-}
-@end
-
-void test4(C0 *c0, int *p) {
-  [c0 m0:p];
-}
-
-// CHECK-LABEL: define void @test5(
-// CHECK: call void {{.*}}(i8* bitcast ({ i8**, i32, i32, i8*, {{.*}} }* @{{.*}} to i8*), i32* nocapture {{.*}})
-// CHECK: call void {{.*}}(i8* {{.*}}, i32* nocapture {{.*}})
-// CHECK: define internal void @{{.*}}(i8* {{.*}}, i32* nocapture {{.*}})
-
-typedef void (^BlockTy2)(__attribute__((noescape)) int *);
-
-void test5(BlockTy2 b, int *p) {
-  ^(int *__attribute__((noescape)) p0){}(p);
-  b(p);
-}
diff --git a/test/Misc/ast-dump-attr.cpp b/test/Misc/ast-dump-attr.cpp
index bf94295..07f9160 100644
--- a/test/Misc/ast-dump-attr.cpp
+++ b/test/Misc/ast-dump-attr.cpp
@@ -180,14 +180,6 @@
 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr5
 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration
 
-namespace TestNoEscape {
-  void noescapeFunc(int *p0, __attribute__((noescape)) int *p1) {}
-  // CHECK: `-FunctionDecl{{.*}} noescapeFunc 'void (int *, __attribute__((noescape)) int *)'
-  // CHECK-NEXT: ParmVarDecl
-  // CHECK-NEXT: ParmVarDecl
-  // CHECK-NEXT: NoEscapeAttr
-}
-
 namespace TestSuppress {
   [[gsl::suppress("at-namespace")]];
   // CHECK: NamespaceDecl{{.*}} TestSuppress
diff --git a/test/Misc/pragma-attribute-supported-attributes-list.test b/test/Misc/pragma-attribute-supported-attributes-list.test
index 5141a96..834dd4c 100644
--- a/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 65 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -33,7 +33,6 @@
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoDebug (SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter)
 // CHECK-NEXT: NoDuplicate (SubjectMatchRule_function)
-// CHECK-NEXT: NoEscape (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
diff --git a/test/Sema/attr-noescape.c b/test/Sema/attr-noescape.c
index d342654..ec367b6 100644
--- a/test/Sema/attr-noescape.c
+++ b/test/Sema/attr-noescape.c
@@ -8,5 +8,5 @@
 
 void foo(__attribute__((noescape)) int *int_ptr,
          __attribute__((noescape)) int (^block)(int),
-         __attribute((noescape)) int integer) { // expected-warning{{'noescape' attribute only applies to pointer arguments}}
+         __attribute((noescape)) int integer) { // expected-warning{{'noescape' attribute ignored on parameter of non-pointer type 'int'}}
 }
diff --git a/test/Sema/noescape.c b/test/Sema/noescape.c
deleted file mode 100644
index 39f3f6f..0000000
--- a/test/Sema/noescape.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-void escapefunc(int *);
-void noescapefunc(__attribute__((noescape)) int *);
-void (*escapefuncptr)(int *);
-void (*noescapefuncptr)(__attribute__((noescape)) int *);
-
-void func_ne(__attribute__((noescape)) int *, int *);
-void func_en(int *, __attribute__((noescape)) int *);
-
-void (*funcptr_ee)(int *, int *);
-void (*funcptr_nn)(__attribute__((noescape)) int *, __attribute__((noescape)) int *);
-
-void test0(int c) {
-  escapefuncptr = &escapefunc;
-  escapefuncptr = &noescapefunc;
-  noescapefuncptr = &escapefunc; // expected-warning {{incompatible function pointer types assigning to 'void (*)(__attribute__((noescape)) int *)' from 'void (*)(int *)'}}
-  noescapefuncptr = &noescapefunc;
-
-  escapefuncptr = c ? &escapefunc : &noescapefunc;
-  noescapefuncptr = c ? &escapefunc : &noescapefunc; // expected-warning {{incompatible function pointer types assigning to 'void (*)(__attribute__((noescape)) int *)' from 'void (*)(int *)'}}
-
-  funcptr_ee = c ? &func_ne : &func_en;
-  funcptr_nn = c ? &func_ne : &func_en; // expected-warning {{incompatible function pointer types assigning to 'void (*)(__attribute__((noescape)) int *, __attribute__((noescape)) int *)' from 'void (*)(int *, int *)'}}
-}
diff --git a/test/SemaObjC/arc-nsconsumed-errors.m b/test/SemaObjC/arc-nsconsumed-errors.m
index fd0d388..62e74aa 100644
--- a/test/SemaObjC/arc-nsconsumed-errors.m
+++ b/test/SemaObjC/arc-nsconsumed-errors.m
@@ -1,8 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 -DOBJCARC %s
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
 // rdar://10187884
 
-#ifdef OBJCARC
 typedef void (^blk)(id arg1, __attribute((ns_consumed)) id arg2);
 typedef void (^blk1)(__attribute((ns_consumed))id arg1, __attribute((ns_consumed)) id arg2);
 blk a = ^void (__attribute((ns_consumed)) id arg1, __attribute((ns_consumed)) id arg2){}; // expected-error {{incompatible block pointer types initializing}}
@@ -20,12 +18,3 @@
 blk1 c3 = ^void (__attribute((ns_consumed)) id arg1, __attribute((ns_consumed)) id arg2){};
 
 blk1 d4 = ^void (id arg1, id arg2) {}; // expected-error {{incompatible block pointer types initializing}}
-#else
-@interface Sub
--(void) m:(id)p; // expected-note {{parameter declared here}}
-@end
-
-@interface Super : Sub
--(void) m:(__attribute__((ns_consumed)) id)p; // expected-warning {{overriding method has mismatched ns_consumed attribute on its parameter}}
-@end
-#endif
diff --git a/test/SemaObjCXX/noescape.mm b/test/SemaObjCXX/noescape.mm
deleted file mode 100644
index 6c5d989..0000000
--- a/test/SemaObjCXX/noescape.mm
+++ /dev/null
@@ -1,90 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++1z %s
-
-typedef void (^BlockTy)();
-
-struct S {
-  int i;
-  void m();
-};
-
-void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
-void noescapeFunc1(id, [[clang::noescape]] BlockTy);
-void noescapeFunc2(__attribute__((noescape)) int *); // expected-note {{previous declaration is here}}
-void noescapeFunc3(__attribute__((noescape)) id);
-void noescapeFunc4(__attribute__((noescape)) int &);
-void noescapeFunc2(int *); // expected-error {{conflicting types for 'noescapeFunc2'}}
-
-void invalidFunc0(int __attribute__((noescape))); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
-void invalidFunc1(int __attribute__((noescape(0)))); // expected-error {{'noescape' attribute takes no arguments}}
-void invalidFunc2(int0 *__attribute__((noescape))); // expected-error {{use of undeclared identifier 'int0'; did you mean 'int'?}}
-void invalidFunc3(__attribute__((noescape)) int (S::*Ty)); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
-void invalidFunc4(__attribute__((noescape)) void (S::*Ty)()); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
-int __attribute__((noescape)) g; // expected-warning {{'noescape' attribute only applies to parameters}}
-
-struct S1 {
-  virtual void m0(int *__attribute__((noescape))); // expected-note {{parameter of overridden method is annotated with __attribute__((noescape))}}
-};
-
-struct S2 : S1 {
-  void m0(int *__attribute__((noescape))) override;
-};
-
-struct S3 : S1 {
-  void m0(int *) override; // expected-warning {{parameter of overriding method should be annotated with __attribute__((noescape))}}
-};
-
-__attribute__((objc_root_class))
-@interface C0
--(void) m0:(int*)__attribute__((noescape)) p; // expected-note {{parameter of overridden method is annotated with __attribute__((noescape))}}
-@end
-
-@implementation C0
--(void) m0:(int*)__attribute__((noescape)) p {}
-@end
-
-@interface C1 : C0
--(void) m0:(int*)__attribute__((noescape)) p;
-@end
-
-@implementation C1 : C0
--(void) m0:(int*)__attribute__((noescape)) p {}
-@end
-
-@interface C2 : C0
--(void) m0:(int*) p; // expected-warning {{parameter of overriding method should be annotated with __attribute__((noescape))}}
-@end
-
-@implementation C2 : C0
--(void) m0:(int*) p {}
-@end
-
-void func0(int *);
-void (*fnptr0)(int *);
-void (*fnptr1)(__attribute__((noescape)) int *);
-template<void (*fn)(int*)> struct S4 {};
-template<void (*fn)(int* __attribute__((noescape)))> struct S5 {};
-
-#if __cplusplus < 201406
-  // expected-note@-4 {{template parameter is declared here}}
-  // expected-note@-4 {{template parameter is declared here}}
-#endif
-
-void test0() {
-  fnptr0 = &func0;
-  fnptr0 = &noescapeFunc2;
-  fnptr1 = &func0; // expected-error {{assigning to 'void (*)(__attribute__((noescape)) int *)' from incompatible type 'void (*)(int *)'}}
-  fnptr1 = &noescapeFunc2;
-  S4<&func0> e0;
-  S4<&noescapeFunc2> e1;
-  S5<&func0> ne0;
-
-#if __cplusplus < 201406
-  // expected-error@-4 {{non-type template argument of type 'void (*)(__attribute__((noescape)) int *)' cannot be converted to a value of type 'void (*)(int *)'}}
-  // expected-error@-4 {{non-type template argument of type 'void (*)(int *)' cannot be converted to a value of type 'void (*)(__attribute__((noescape)) int *)'}}
-#else
-  // expected-error@-6 {{value of type 'void (*)(int *)' is not implicitly convertible to 'void (*)(__attribute__((noescape)) int *)'}}
-#endif
-
-  S5<&noescapeFunc2> ne1;
-}