erik.pilkington updated this revision to Diff 334801.
erik.pilkington added a comment.
In D99661#2662601 <https://reviews.llvm.org/D99661#2662601>, @ahatanak wrote:
> Should we try to restore the behavior prior to
> https://reviews.llvm.org/rG09abecef7bbfda18d34f046954eaa4d491062839 as much
> as we can? Or that's not important?
Sure, the new patch starts iterating through the redeclarations starting at the
most recent declaration, which should mimic the old behaviour. I'm not sure it
matters, having multiple `objc_bridge` attributes has never actually worked
(`objc_bridge` attributes appearing earlier get "shadowed" by the most recent
one), i.e. in your testcase `CFStringGetLength((__bridge CFStringRef)(NSError
*)0);` has always lead to a -Wbridge-cast diagnostic.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99661/new/
https://reviews.llvm.org/D99661
Files:
clang/lib/Sema/SemaExprObjC.cpp
clang/test/SemaObjCXX/bridge-cast-redecl.mm
Index: clang/test/SemaObjCXX/bridge-cast-redecl.mm
===================================================================
--- /dev/null
+++ 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);
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===================================================================
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -3847,9 +3847,12 @@
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;
}
Index: clang/test/SemaObjCXX/bridge-cast-redecl.mm
===================================================================
--- /dev/null
+++ 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);
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===================================================================
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -3847,9 +3847,12 @@
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;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits