From 6fcc7efad066d6f3804196f3d3fbddd6a0a485cb Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 17 Jun 2014 10:41:49 +0200 Subject: Fix logic to obtain callee's FunctionProtoType (if any) Change-Id: I1bfdd865429cc6fa89ea3b6b4fc132b5d5b57b0d --- compilerplugins/clang/implicitboolconversion.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'compilerplugins/clang/implicitboolconversion.cxx') diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index 6503ca8d2860..d8ef00e6dbef 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -170,17 +170,22 @@ bool ImplicitBoolConversion::TraverseCallExpr(CallExpr * expr) { FunctionDecl const * fd = dyn_cast(d); if (fd != nullptr && fd->isExternC()) { ext = true; - PointerType const * pt = dyn_cast(fd->getType()); - t = (pt == nullptr ? fd->getType() : pt->getPointeeType()) - ->getAs(); + PointerType const * pt = fd->getType()->getAs(); + QualType t2(pt == nullptr ? fd->getType() : pt->getPointeeType()); + t = t2->getAs(); + assert( + t != nullptr || !compiler.getLangOpts().CPlusPlus + || (fd->getBuiltinID() != Builtin::NotBuiltin + && isa(t2))); + // __builtin_*s have no proto type? } else { VarDecl const * vd = dyn_cast(d); if (vd != nullptr && vd->isExternC()) { ext = true; - PointerType const * pt = dyn_cast(vd->getType()); + PointerType const * pt = vd->getType()->getAs(); t = (pt == nullptr ? vd->getType() : pt->getPointeeType()) - ->getAs(); + ->castAs(); } } } @@ -192,7 +197,7 @@ bool ImplicitBoolConversion::TraverseCallExpr(CallExpr * expr) { [&i](Expr * e) { return i == e->IgnoreParens(); }); if (j == expr->arg_end()) { reportWarning(i); - } else { + } else if (t != nullptr) { std::ptrdiff_t n = j - expr->arg_begin(); assert(n >= 0); assert( -- cgit