Author: Erik Pilkington Date: 2021-04-05T11:41:40-04:00 New Revision: 803b79221edfc2517e6bfc373e5f55609565b0e4
URL: https://github.com/llvm/llvm-project/commit/803b79221edfc2517e6bfc373e5f55609565b0e4 DIFF: https://github.com/llvm/llvm-project/commit/803b79221edfc2517e6bfc373e5f55609565b0e4.diff LOG: [SemaObjC] Fix a -Wbridge-cast false-positive Clang used to emit a bad -Wbridge-cast diagnostic on the cast in the attached test. This was because, after 09abecef7, struct __CFString was not added to lookup, so the objc_bridge attribute wasn't getting duplicated onto the most recent declaration, causing us to fail to find it in getObjCBridgeAttr. This patch fixes this by instead walking through the redeclarations to find an appropriate bridge attribute. rdar://72823399 Differential revision: https://reviews.llvm.org/D99661 Added: clang/test/SemaObjCXX/bridge-cast-redecl.mm Modified: clang/lib/Sema/SemaExprObjC.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index f5456ee0711e5..71c150027cdd6 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -3847,9 +3847,12 @@ static inline T *getObjCBridgeAttr(const TypedefType *TD) { QualType QT = TDNDecl->getUnderlyingType(); if (QT->isPointerType()) { QT = QT->getPointeeType(); - if (const RecordType *RT = QT->getAs<RecordType>()) - if (RecordDecl *RD = RT->getDecl()->getMostRecentDecl()) - return RD->getAttr<T>(); + if (const RecordType *RT = QT->getAs<RecordType>()) { + for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) { + if (auto *attr = Redecl->getAttr<T>()) + return attr; + } + } } return nullptr; } diff --git a/clang/test/SemaObjCXX/bridge-cast-redecl.mm b/clang/test/SemaObjCXX/bridge-cast-redecl.mm new file mode 100644 index 0000000000000..c640e52922938 --- /dev/null +++ b/clang/test/SemaObjCXX/bridge-cast-redecl.mm @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=gnu++17 -verify %s + +// expected-no-diagnostics + +typedef const struct __CFString * CFStringRef; + +extern "C" { + typedef const struct __attribute__((objc_bridge(NSString))) __CFString * CFStringRef; + typedef struct __attribute__((objc_bridge_mutable(NSMutableString))) __CFString * CFMutableStringRef; +} + +@interface NSString @end +@interface NSMutableString : NSString @end + +void CFStringGetLength(CFStringRef theString); + +int main() { + CFStringGetLength((__bridge CFStringRef)(NSString *)0); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits