summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/Builtins.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-07-16 02:11:15 +0000
committerTed Kremenek <kremenek@apple.com>2010-07-16 02:11:15 +0000
commit5932c35138947e48c966b198858e51eafa4e725c (patch)
tree8c954f5f0b10ec9ea5edb0edf288321612e49cf1 /clang/lib/Basic/Builtins.cpp
parent103c4ebea5948630aa777cc9c0c40568ad16a5d6 (diff)
downloadbcm5719-llvm-5932c35138947e48c966b198858e51eafa4e725c.tar.gz
bcm5719-llvm-5932c35138947e48c966b198858e51eafa4e725c.zip
Add builtin definition for scanf, including extending the builtin encoding to
represent builtins that have the "scanf" attribution (via the format attribute) just like we do with printf functions. Follow-up work is needed to add similar support for fscanf et al. This is to support format-string checking for scanf functions. llvm-svn: 108499
Diffstat (limited to 'clang/lib/Basic/Builtins.cpp')
-rw-r--r--clang/lib/Basic/Builtins.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index 1a3293775ed..040cdb5d55f 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -93,3 +93,23 @@ Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx,
return true;
}
+// FIXME: Refactor with isPrintfLike.
+bool
+Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx,
+ bool &HasVAListArg) {
+ const char *Scanf = strpbrk(GetRecord(ID).Attributes, "sS");
+ if (!Scanf)
+ return false;
+
+ HasVAListArg = (*Scanf == 'S');
+
+ ++Scanf;
+ assert(*Scanf == ':' && "s or S specifier must have be followed by a ':'");
+ ++Scanf;
+
+ assert(strchr(Scanf, ':') && "printf specifier must end with a ':'");
+ FormatIdx = strtol(Scanf, 0, 10);
+ return true;
+}
+
+
OpenPOWER on IntegriCloud