From e333adb1ff0ffc36a78e50dc4061c1dfb0593d71 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 12 Sep 2014 14:46:23 +0200 Subject: loplugin:salbool: exclude sal_Bool vars passed to non-const ref Change-Id: I45b323b326cc56cfc48e0abaa52d51fd86adbf79 --- compilerplugins/clang/salbool.cxx | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx index 5eddba6b5379..6cca0faa3455 100644 --- a/compilerplugins/clang/salbool.cxx +++ b/compilerplugins/clang/salbool.cxx @@ -119,6 +119,8 @@ public: bool VisitUnaryAddrOf(UnaryOperator const * op); + bool VisitCallExpr(CallExpr * expr); + bool VisitCStyleCastExpr(CStyleCastExpr * expr); bool VisitCXXStaticCastExpr(CXXStaticCastExpr * expr); @@ -210,6 +212,51 @@ bool SalBool::VisitUnaryAddrOf(UnaryOperator const * op) { return true; } +bool SalBool::VisitCallExpr(CallExpr * expr) { + Decl const * d = expr->getCalleeDecl(); + FunctionProtoType const * ft = nullptr; + if (d != nullptr) { + FunctionDecl const * fd = dyn_cast(d); + if (fd != nullptr) { + PointerType const * pt = fd->getType()->getAs(); + QualType t2(pt == nullptr ? fd->getType() : pt->getPointeeType()); + ft = t2->getAs(); + assert( + ft != 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) { + PointerType const * pt = vd->getType()->getAs(); + ft = (pt == nullptr ? vd->getType() : pt->getPointeeType()) + ->getAs(); + } + } + } + if (ft != nullptr) { + for (unsigned i = 0; i != compat::getNumParams(*ft); ++i) { + QualType t(compat::getParamType(*ft, i)); + if (t->isLValueReferenceType()) { + t = t.getNonReferenceType(); + if (!t.isConstQualified() && isSalBool(t) + && i < expr->getNumArgs()) + { + DeclRefExpr * ref = dyn_cast(expr->getArg(i)); + if (ref != nullptr) { + VarDecl const * d = dyn_cast(ref->getDecl()); + if (d != nullptr) { + varDecls_.erase(d); + } + } + } + } + } + } + return true; +} + bool SalBool::VisitCStyleCastExpr(CStyleCastExpr * expr) { if (ignoreLocation(expr)) { return true; -- cgit v1.2.3