[PATCH] D99661: [SemaObjC] Fix a -Wbridge-cast false-positive
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 5 08:43:09 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG803b79221edf: [SemaObjC] Fix a -Wbridge-cast false-positive (authored by erik.pilkington).
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
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;
+}
+
+ at interface NSString @end
+ at 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99661.335265.patch
Type: text/x-patch
Size: 1451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210405/516142e8/attachment.bin>
More information about the cfe-commits
mailing list