aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-14 00:32:47 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-14 00:32:47 +0000
commita316e7b735b12ce6b34961a9dcfaae34f4b08d29 (patch)
treea0ea5c12323051f468421c77c8a9eeb572a6ff60 /lib/Sema/SemaChecking.cpp
parent7e4966e92dcf14567b59f5df4714b6562af57480 (diff)
Extend builtin "attribute" syntax to include a notation for
printf-like functions, both builtin functions and those in the C library. The function-call checker now queries this attribute do determine if we have a printf-like function, rather than scanning through the list of "known functions IDs". However, there are 5 functions they are not yet "builtins", so the function-call checker handles them specifically still: - fprintf and vfprintf: the builtins mechanism cannot (yet) express FILE* arguments, so these can't be encoded. - NSLog: the builtins mechanism cannot (yet) express NSString* arguments, so this (and NSLogv) can't be encoded. - asprintf and vasprintf: these aren't part of the C99 standard library, so we really shouldn't be defining them as builtins in the general case (and we don't seem to have the machinery to make them builtins only on certain targets and depending on whether extensions are enabled). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64512 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp52
1 files changed, 21 insertions, 31 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index e058861283..ab71255496 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -77,40 +77,30 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
// more efficient. For example, just map function ids to custom
// handlers.
- // Search the KnownFunctionIDs for the identifier.
- unsigned i = 0, e = id_num_known_functions;
- for (; i != e; ++i) { if (KnownFunctionIDs[i] == FnInfo) break; }
- if (i == e) return move(TheCallResult);
-
// Printf checking.
- if (i <= id_vprintf) {
- // Retrieve the index of the format string parameter and determine
- // if the function is passed a va_arg argument.
- unsigned format_idx = 0;
- bool HasVAListArg = false;
-
- switch (i) {
- default: assert(false && "No format string argument index.");
- case id_NSLog: format_idx = 0; break;
- case id_asprintf: format_idx = 1; break;
- case id_fprintf: format_idx = 1; break;
- case id_printf: format_idx = 0; break;
- case id_snprintf: format_idx = 2; break;
- case id_snprintf_chk: format_idx = 4; break;
- case id_sprintf: format_idx = 1; break;
- case id_sprintf_chk: format_idx = 3; break;
- case id_vasprintf: format_idx = 1; HasVAListArg = true; break;
- case id_vfprintf: format_idx = 1; HasVAListArg = true; break;
- case id_vsnprintf: format_idx = 2; HasVAListArg = true; break;
- case id_vsnprintf_chk: format_idx = 4; HasVAListArg = true; break;
- case id_vsprintf: format_idx = 1; HasVAListArg = true; break;
- case id_vsprintf_chk: format_idx = 3; HasVAListArg = true; break;
- case id_vprintf: format_idx = 0; HasVAListArg = true; break;
- }
-
- CheckPrintfArguments(TheCall, HasVAListArg, format_idx);
+ unsigned format_idx = 0;
+ bool HasVAListArg = false;
+ if (FDecl->getBuiltinID() &&
+ Context.BuiltinInfo.isPrintfLike(FDecl->getBuiltinID(), format_idx,
+ HasVAListArg)) {
+ // Found a printf builtin.
+ } else if (FnInfo == KnownFunctionIDs[id_NSLog]) {
+ format_idx = 0;
+ HasVAListArg = false;
+ } else if (FnInfo == KnownFunctionIDs[id_asprintf] ||
+ FnInfo == KnownFunctionIDs[id_fprintf]) {
+ format_idx = 1;
+ HasVAListArg = false;
+ } else if (FnInfo == KnownFunctionIDs[id_vasprintf] ||
+ FnInfo == KnownFunctionIDs[id_vfprintf]) {
+ format_idx = 1;
+ HasVAListArg = true;
+ } else {
+ return move(TheCallResult);
}
+ CheckPrintfArguments(TheCall, HasVAListArg, format_idx);
+
return move(TheCallResult);
}