From: Ted Kremenek Date: Tue, 14 Jun 2011 22:56:51 +0000 (+0000) Subject: [format strings] correctly suggest correct type for '%@' specifiers. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133024 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp index c1b5ea8a65..be214e0d86 100644 --- a/lib/Analysis/FormatString.cpp +++ b/lib/Analysis/FormatString.cpp @@ -300,7 +300,8 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const { argTy->isNullPtrType(); case ObjCPointerTy: - return argTy->getAs() != NULL; + return argTy->getAs() != NULL || + argTy->getAs() != NULL; } // FIXME: Should be unreachable, but Clang is currently emitting diff --git a/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp index 00b0b279e4..270308a08f 100644 --- a/lib/Analysis/PrintfFormatString.cpp +++ b/lib/Analysis/PrintfFormatString.cpp @@ -348,6 +348,8 @@ ArgTypeResult PrintfSpecifier::getArgType(ASTContext &Ctx) const { return Ctx.WCharTy; case ConversionSpecifier::pArg: return ArgTypeResult::CPointerTy; + case ConversionSpecifier::ObjCObjArg: + return ArgTypeResult::ObjCPointerTy; default: break; } diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index d89f50afa9..dd49cf7a93 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -38,6 +38,7 @@ int printf(const char * restrict, ...) ; void check_nslog(unsigned k) { NSLog(@"%d%%", k); // no-warning NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{invalid conversion specifier 'b'}} + NSLog(@"%@", "a"); // expected-warning {{conversion specifies type 'id' but the argument has type 'char *'}} } // Check type validation