Sfoglia il codice sorgente

Implicitly annotate __CFStringMakeConstantString with format_arg(1).

We handled the builtin version of this function in r157968, but the builtin
isn't used when compiling as -fno-constant-cfstrings.

This should complete <rdar://problem/6157200>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161525 91177308-0d34-0410-b5e6-96231b3b80d8
Jordan Rose 13 anni fa
parent
commit
8a64f88aa9
2 ha cambiato i file con 10 aggiunte e 3 eliminazioni
  1. 7 0
      lib/Sema/SemaDecl.cpp
  2. 3 3
      test/SemaObjC/format-strings-objc.m

+ 7 - 0
lib/Sema/SemaDecl.cpp

@@ -7974,6 +7974,13 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
                                              "printf", 2,
                                              Name->isStr("vasprintf") ? 0 : 3));
   }
+
+  if (Name->isStr("__CFStringMakeConstantString")) {
+    // We already have a __builtin___CFStringMakeConstantString,
+    // but builds that use -fno-constant-cfstrings don't go through that.
+    if (!FD->getAttr<FormatArgAttr>())
+      FD->addAttr(::new (Context) FormatArgAttr(FD->getLocation(), Context, 1));
+  }
 }
 
 TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T,

+ 3 - 3
test/SemaObjC/format-strings-objc.m

@@ -34,9 +34,9 @@ extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((for
 #define CFSTR(cStr)  ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
 
 // This function is used instead of the builtin if -fno-constant-cfstrings.
-// The definition on Mac OS X is NOT annotated with format_arg as of 10.7,
-// but if it were, we want the same checking behavior as with the builtin.
-extern CFStringRef __CFStringMakeConstantString(const char *) __attribute__((format_arg(1)));
+// The definition on Mac OS X is NOT annotated with format_arg as of 10.8,
+// but clang will implicitly add the attribute if it's not written.
+extern CFStringRef __CFStringMakeConstantString(const char *);
 
 int printf(const char * restrict, ...) ;