[PATCH] D112670: __attribute__((format_arg(__NSString__, N))) does not support instancetype in NSString interface
FĂ©lix Cloutier via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 28 20:32:48 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a5f7437720e: format_arg attribute should allow instancetype in NSString definition (authored by fcloutier).
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
- at class NSString;
+ at interface NSString
++(instancetype)stringWithCString:(const char *)cstr __attribute__((format_arg(1)));
++(instancetype)stringWithString:(NSString *)cstr __attribute__((format_arg(1)));
+ at end
+
+ at protocol MaybeString
+-(instancetype)maybeString:(const char *)cstr __attribute__((format_arg(1))); // expected-error {{function does not return string type}}
+ at 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() ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112670.383229.patch
Type: text/x-patch
Size: 1511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211029/82e46473/attachment.bin>
More information about the cfe-commits
mailing list