From 25e4e9694ce12152693e9d272557e5d546becd40 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 12 Sep 2016 08:20:17 +0200 Subject: handle nullptr in various clang plugins since we are using it so widely now, instead of NULL Change-Id: I990ff1334f657663e8791ab064d69e56636fe6e7 --- compilerplugins/clang/defaultparams.cxx | 19 ++++++++++++++++--- compilerplugins/clang/overrideparam.cxx | 16 ++++++++++++++-- compilerplugins/clang/singlevalfields.cxx | 3 +++ 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/defaultparams.cxx b/compilerplugins/clang/defaultparams.cxx index de030870a7f9..7755b3749661 100644 --- a/compilerplugins/clang/defaultparams.cxx +++ b/compilerplugins/clang/defaultparams.cxx @@ -26,6 +26,8 @@ public: virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } bool VisitCallExpr(CallExpr * callExpr); +private: + bool evaluate(const Expr* expr, APSInt& x); }; bool DefaultParams::VisitCallExpr(CallExpr * callExpr) { @@ -69,9 +71,7 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) { if (!found) { APSInt x1, x2; - if (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext()) - && arg->EvaluateAsInt(x2, compiler.getASTContext()) - && x1 == x2) + if (evaluate(defaultArgExpr, x1) && evaluate(arg, x2) && x1 == x2) { found = true; } @@ -108,6 +108,19 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) { return true; } +bool DefaultParams::evaluate(const Expr* expr, APSInt& x) +{ + if (isa(expr)) { + x = 0; + return true; + } + if (expr->EvaluateAsInt(x, compiler.getASTContext())) + { + return true; + } + return false; +} + loplugin::Plugin::Registration< DefaultParams > X("defaultparams"); } diff --git a/compilerplugins/clang/overrideparam.cxx b/compilerplugins/clang/overrideparam.cxx index aca1e952ba66..c9d836c91b4e 100644 --- a/compilerplugins/clang/overrideparam.cxx +++ b/compilerplugins/clang/overrideparam.cxx @@ -37,6 +37,7 @@ public: private: bool hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const ParmVarDecl * superParmVarDecl); + bool evaluate(const Expr* expr, APSInt& x); }; void OverrideParam::run() @@ -155,8 +156,7 @@ bool OverrideParam::hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const return true; } APSInt x1, x2; - if (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext()) - && superDefaultArgExpr->EvaluateAsInt(x2, compiler.getASTContext())) + if (evaluate(defaultArgExpr, x1) && evaluate(superDefaultArgExpr, x2)) { return x1 == x2; } @@ -186,6 +186,18 @@ bool OverrideParam::hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const #endif } +bool OverrideParam::evaluate(const Expr* expr, APSInt& x) +{ + if (expr->EvaluateAsInt(x, compiler.getASTContext())) + { + return true; + } + if (isa(expr)) { + x = 0; + return true; + } + return false; +} loplugin::Plugin::Registration< OverrideParam > X("overrideparam"); diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx index 699daaada5a8..aa3aa316443f 100644 --- a/compilerplugins/clang/singlevalfields.cxx +++ b/compilerplugins/clang/singlevalfields.cxx @@ -474,6 +474,9 @@ std::string SingleValFields::getExprValue(const Expr* arg) { return x1.toString(10); } + if (isa(arg)) { + return "0"; + } return "?"; } -- cgit