diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-07-16 02:11:15 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-07-16 02:11:15 +0000 |
commit | bee05c1206dcd525e0a1f066d166ad3e972a500e (patch) | |
tree | c2fc54c7b3cd70cf93f13ae3ac126ca00b4111eb /lib/Basic/Builtins.cpp | |
parent | 6d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108499 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/Builtins.cpp')
-rw-r--r-- | lib/Basic/Builtins.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Basic/Builtins.cpp b/lib/Basic/Builtins.cpp index 1a3293775e..040cdb5d55 100644 --- a/lib/Basic/Builtins.cpp +++ b/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; +} + + |