summaryrefslogtreecommitdiffstats
path: root/clang/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
commitaa5e5fd2f43f3b66565108bb7182d5575d9fe3db (patch)
tree211fc764c5d854be97706751029927a4d1af2167 /clang/lib/Sema/SemaChecking.cpp
parentaee88e46c12004c000cb8f37f43cc8daeaf53475 (diff)
downloadbcm5719-llvm-aa5e5fd2f43f3b66565108bb7182d5575d9fe3db.tar.gz
bcm5719-llvm-aa5e5fd2f43f3b66565108bb7182d5575d9fe3db.zip
add support for FreeBSD's format(printf0,x,y) attribute; allows null format string.
llvm-svn: 78276
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d6095fc2ae5..949c33dfff8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/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 =
OpenPOWER on IntegriCloud