diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3389,7 +3389,8 @@ } Ty = getFunctionOrMethodResultType(D); // replace instancetype with the class type - if (Ty.getTypePtr() == S.Context.getObjCInstanceTypeDecl()->getTypeForDecl()) + auto Instancetype = S.Context.getObjCInstanceTypeDecl()->getTypeForDecl(); + if (Ty->getAs() == Instancetype) if (auto *OMD = dyn_cast(D)) if (auto *Interface = OMD->getClassInterface()) Ty = S.Context.getObjCObjectPointerType( diff --git a/clang/test/SemaObjC/format-arg-attribute.m b/clang/test/SemaObjC/format-arg-attribute.m --- a/clang/test/SemaObjC/format-arg-attribute.m +++ b/clang/test/SemaObjC/format-arg-attribute.m @@ -2,7 +2,10 @@ @interface NSString +(instancetype)stringWithCString:(const char *)cstr __attribute__((format_arg(1))); -+(instancetype)stringWithString:(NSString *)cstr __attribute__((format_arg(1))); +-(instancetype)initWithString:(NSString *)str __attribute__((format_arg(1))); + ++(instancetype _Nonnull)nonNullableString:(NSString *)str __attribute__((format_arg(1))); ++(instancetype _Nullable)nullableString:(NSString *)str __attribute__((format_arg(1))); @end @protocol MaybeString