fcloutier updated this revision to Diff 383227.
fcloutier added a comment.
Add test for a protocol method with `format_arg`, second NSString method
accepting a NSString instead of a C string
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112670/new/
https://reviews.llvm.org/D112670
Files:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaObjC/format-arg-attribute.m
Index: clang/test/SemaObjC/format-arg-attribute.m
===================================================================
--- clang/test/SemaObjC/format-arg-attribute.m
+++ clang/test/SemaObjC/format-arg-attribute.m
@@ -1,6 +1,14 @@
// RUN: %clang_cc1 -verify -fsyntax-only %s
-@class NSString;
+@interface NSString
++(instancetype)stringWithCString:(const char *)cstr
__attribute__((format_arg(1)));
++(instancetype)stringWithString:(NSString *)cstr
__attribute__((format_arg(1)));
+@end
+
+@protocol MaybeString
+-(instancetype)maybeString:(const char *)cstr __attribute__((format_arg(1)));
// expected-error {{function does not return string type}}
+@end
+
@class NSAttributedString;
extern NSString *fa2 (const NSString *) __attribute__((format_arg(1)));
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3388,6 +3388,12 @@
return;
}
Ty = getFunctionOrMethodResultType(D);
+ // replace instancetype with the class type
+ if (Ty.getTypePtr() == S.Context.getObjCInstanceTypeDecl()->getTypeForDecl())
+ if (auto *OMD = dyn_cast<ObjCMethodDecl>(D))
+ if (auto *Interface = OMD->getClassInterface())
+ Ty = S.Context.getObjCObjectPointerType(
+ QualType(Interface->getTypeForDecl(), 0));
if (!isNSStringType(Ty, S.Context, /*AllowNSAttributedString=*/true) &&
!isCFStringType(Ty, S.Context) &&
(!Ty->isPointerType() ||
Index: clang/test/SemaObjC/format-arg-attribute.m
===================================================================
--- clang/test/SemaObjC/format-arg-attribute.m
+++ clang/test/SemaObjC/format-arg-attribute.m
@@ -1,6 +1,14 @@
// RUN: %clang_cc1 -verify -fsyntax-only %s
-@class NSString;
+@interface NSString
++(instancetype)stringWithCString:(const char *)cstr __attribute__((format_arg(1)));
++(instancetype)stringWithString:(NSString *)cstr __attribute__((format_arg(1)));
+@end
+
+@protocol MaybeString
+-(instancetype)maybeString:(const char *)cstr __attribute__((format_arg(1))); // expected-error {{function does not return string type}}
+@end
+
@class NSAttributedString;
extern NSString *fa2 (const NSString *) __attribute__((format_arg(1)));
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3388,6 +3388,12 @@
return;
}
Ty = getFunctionOrMethodResultType(D);
+ // replace instancetype with the class type
+ if (Ty.getTypePtr() == S.Context.getObjCInstanceTypeDecl()->getTypeForDecl())
+ if (auto *OMD = dyn_cast<ObjCMethodDecl>(D))
+ if (auto *Interface = OMD->getClassInterface())
+ Ty = S.Context.getObjCObjectPointerType(
+ QualType(Interface->getTypeForDecl(), 0));
if (!isNSStringType(Ty, S.Context, /*AllowNSAttributedString=*/true) &&
!isCFStringType(Ty, S.Context) &&
(!Ty->isPointerType() ||
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits