aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorRyan Flynn <pizza@parseerror.com>2009-08-06 03:00:50 +0000
committerRyan Flynn <pizza@parseerror.com>2009-08-06 03:00:50 +0000
commit4403a5e1f956fa86d515492dbe7c7a2817d8780d (patch)
tree0a35faeffe2d9d92159c224b28961b39adb6bf9f /lib/Sema/SemaChecking.cpp
parent67d1a67f3db2f1aa69083c5c94164d6e0ee05b32 (diff)
add support for FreeBSD's format(printf0,x,y) attribute; allows null format string.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78276 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index d6095fc2ae..949c33dfff 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -84,6 +84,21 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
}
}
+/// CheckablePrintfAttr - does a function call have a "printf" attribute
+/// and arguments that merit checking?
+bool Sema::CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall) {
+ if (Format->getType() == "printf") return true;
+ if (Format->getType() == "printf0") {
+ // printf0 allows null "format" string; if so don't check format/args
+ unsigned format_idx = Format->getFormatIdx() - 1;
+ if (format_idx < TheCall->getNumArgs()) {
+ Expr *Format = TheCall->getArg(format_idx)->IgnoreParenCasts();
+ if (!Format->isNullPointerConstant(Context))
+ return true;
+ }
+ }
+ return false;
+}
/// CheckFunctionCall - Check a direct function call for various correctness
/// and safety properties not strictly enforced by the C type system.
@@ -167,7 +182,7 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
// Printf checking.
if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>()) {
- if (Format->getType() == "printf") {
+ if (CheckablePrintfAttr(Format, TheCall)) {
bool HasVAListArg = Format->getFirstArg() == 0;
if (!HasVAListArg) {
if (const FunctionProtoType *Proto
@@ -201,7 +216,7 @@ Sema::CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall) {
QualType Ty = V->getType();
if (!Ty->isBlockPointerType())
return move(TheCallResult);
- if (Format->getType() == "printf") {
+ if (CheckablePrintfAttr(Format, TheCall)) {
bool HasVAListArg = Format->getFirstArg() == 0;
if (!HasVAListArg) {
const FunctionType *FT =