[cfe-commits] r149907 - in /cfe/trunk: lib/Analysis/FormatString.cpp test/SemaObjC/format-strings-objc.m
Ted Kremenek
kremenek at apple.com
Mon Feb 6 13:45:29 PST 2012
Author: kremenek
Date: Mon Feb 6 15:45:29 2012
New Revision: 149907
URL: http://llvm.org/viewvc/llvm-project?rev=149907&view=rev
Log:
Tweak format string checking to work with %@ and ObjC toll-free bridging. <rdar://problem/10814120>
Modified:
cfe/trunk/lib/Analysis/FormatString.cpp
cfe/trunk/test/SemaObjC/format-strings-objc.m
Modified: cfe/trunk/lib/Analysis/FormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=149907&r1=149906&r2=149907&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/FormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/FormatString.cpp Mon Feb 6 15:45:29 2012
@@ -336,9 +336,23 @@
return argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
argTy->isNullPtrType();
- case ObjCPointerTy:
- return argTy->getAs<ObjCObjectPointerType>() ||
- argTy->getAs<BlockPointerType>();
+ case ObjCPointerTy: {
+ if (argTy->getAs<ObjCObjectPointerType>() ||
+ argTy->getAs<BlockPointerType>())
+ return true;
+
+ // Handle implicit toll-free bridging.
+ if (const PointerType *PT = argTy->getAs<PointerType>()) {
+ // Things such as CFTypeRef are really just opaque pointers
+ // to C structs representing CF types that can often be bridged
+ // to Objective-C objects. Since the compiler doesn't know which
+ // structs can be toll-free bridged, we just accept them all.
+ QualType pointee = PT->getPointeeType();
+ if (pointee->getAsStructureType() || pointee->isVoidType())
+ return true;
+ }
+ return false;
+ }
}
llvm_unreachable("Invalid ArgTypeResult Kind!");
Modified: cfe/trunk/test/SemaObjC/format-strings-objc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/format-strings-objc.m?rev=149907&r1=149906&r2=149907&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/format-strings-objc.m (original)
+++ cfe/trunk/test/SemaObjC/format-strings-objc.m Mon Feb 6 15:45:29 2012
@@ -146,3 +146,8 @@
const wchar_t wchar_data = L'a';
NSLog(@"%C", wchar_data); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'wchar_t'}}
}
+
+// Test that %@ works with toll-free bridging (<rdar://problem/10814120>).
+void test_toll_free_bridging(CFStringRef x) {
+ NSLog(@"%@", x); // no-warning
+}
More information about the cfe-commits
mailing list