aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaChecking.cpp7
-rw-r--r--test/SemaObjC/format-strings-objc.m10
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index b31a5b8a84..7a852aefad 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -1586,6 +1586,13 @@ void Sema::CheckFormatArguments(Expr **Args, unsigned NumArgs,
format_idx, firstDataArg, Type))
return; // Literal format string found, check done!
+ // Do not emit diag when the string param is a macro expansion and the
+ // format is either NSString or CFString. This is a hack to prevent
+ // diag when using the NSLocalizedString and CFCopyLocalizedString macros
+ // which are usually used in place of NS and CF string literals.
+ if (Type == FST_NSString && Args[format_idx]->getLocStart().isMacroID())
+ return;
+
// If there are no arguments specified, warn with -Wformat-security, otherwise
// warn only with -Wformat-nonliteral.
if (NumArgs == format_idx+1)
diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m
index e130b1803f..5ab4d8bf3b 100644
--- a/test/SemaObjC/format-strings-objc.m
+++ b/test/SemaObjC/format-strings-objc.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wformat-nonliteral -fsyntax-only -verify %s
//===----------------------------------------------------------------------===//
// The following code is reduced using delta-debugging from
@@ -107,3 +107,11 @@ NSString *test_literal_propagation(void) {
NSString * ns3 = ns1;
NSLog(ns3); // expected-warning {{format string is not a string literal}}}
}
+
+// Do not emit warnings when using NSLocalizedString
+extern NSString *GetLocalizedString(NSString *str);
+#define NSLocalizedString(key) GetLocalizedString(key)
+
+void check_NSLocalizedString() {
+ [Foo fooWithFormat:NSLocalizedString(@"format"), @"arg"]; // no-warning
+}