[cfe-commits] r148873 - in /cfe/trunk: include/clang/Basic/Builtins.def lib/Sema/SemaDecl.cpp test/SemaObjC/builtin_objc_nslog.m
Jean-Daniel Dupas
devlists at shadowlab.org
Tue Jan 24 14:32:46 PST 2012
Author: jddupas
Date: Tue Jan 24 16:32:46 2012
New Revision: 148873
URL: http://llvm.org/viewvc/llvm-project?rev=148873&view=rev
Log:
Replace a hack to handle NSLog/NSLogv in sema by declaring them as Library Builtins.
Added:
cfe/trunk/test/SemaObjC/builtin_objc_nslog.m (with props)
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=148873&r1=148872&r2=148873&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Jan 24 16:32:46 2012
@@ -756,6 +756,11 @@
BUILTIN(__builtin_objc_memmove_collectable, "v*v*vC*z", "nF")
+// void NSLog(NSString *fmt, ...)
+LIBBUILTIN(NSLog, "vG.", "fp:0:", "Foundation/NSObjCRuntime.h", OBJC_LANG)
+// void NSLogv(NSString *fmt, va_list args)
+LIBBUILTIN(NSLogv, "vGa", "fP:0:", "Foundation/NSObjCRuntime.h", OBJC_LANG)
+
// Builtin math library functions
LIBBUILTIN(pow, "ddd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(powl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=148873&r1=148872&r2=148873&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 24 16:32:46 2012
@@ -7420,10 +7420,16 @@
unsigned FormatIdx;
bool HasVAListArg;
if (Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) {
- if (!FD->getAttr<FormatAttr>())
+ if (!FD->getAttr<FormatAttr>()) {
+ const char *fmt = "printf";
+ unsigned int NumParams = FD->getNumParams();
+ if (FormatIdx < NumParams && // NumParams may be 0 (e.g. vfprintf)
+ FD->getParamDecl(FormatIdx)->getType()->isObjCObjectPointerType())
+ fmt = "NSString";
FD->addAttr(::new (Context) FormatAttr(FD->getLocation(), Context,
- "printf", FormatIdx+1,
+ fmt, FormatIdx+1,
HasVAListArg ? 0 : FormatIdx+2));
+ }
}
if (Context.BuiltinInfo.isScanfLike(BuiltinID, FormatIdx,
HasVAListArg)) {
@@ -7464,16 +7470,7 @@
} else
return;
- if (Name->isStr("NSLog") || Name->isStr("NSLogv")) {
- // FIXME: NSLog and NSLogv should be target specific
- if (const FormatAttr *Format = FD->getAttr<FormatAttr>()) {
- // FIXME: We known better than our headers.
- const_cast<FormatAttr *>(Format)->setType(Context, "printf");
- } else
- FD->addAttr(::new (Context) FormatAttr(FD->getLocation(), Context,
- "printf", 1,
- Name->isStr("NSLogv") ? 0 : 2));
- } else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) {
+ if (Name->isStr("asprintf") || Name->isStr("vasprintf")) {
// FIXME: asprintf and vasprintf aren't C99 functions. Should they be
// target-specific builtins, perhaps?
if (!FD->getAttr<FormatAttr>())
Added: cfe/trunk/test/SemaObjC/builtin_objc_nslog.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/builtin_objc_nslog.m?rev=148873&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/builtin_objc_nslog.m (added)
+++ cfe/trunk/test/SemaObjC/builtin_objc_nslog.m Tue Jan 24 16:32:46 2012
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify
+
+#include <stdarg.h>
+
+void f1(id arg) {
+ NSLog(@"%@", arg); // expected-warning {{implicitly declaring C library function 'NSLog' with type 'void (id, ...)'}} \
+ // expected-note {{please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLog'}}
+}
+
+void f2(id str, va_list args) {
+ NSLogv(@"%@", args); // expected-warning {{implicitly declaring C library function 'NSLogv' with type 'void (id, __va_list_tag *)'}} \
+ // expected-note {{please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLogv'}}
+}
Propchange: cfe/trunk/test/SemaObjC/builtin_objc_nslog.m
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/SemaObjC/builtin_objc_nslog.m
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=utf-8
More information about the cfe-commits
mailing list