summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2016-09-12 08:20:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2016-09-12 08:22:03 +0200
commit25e4e9694ce12152693e9d272557e5d546becd40 (patch)
tree260c61bc6162c21ba66eca24743b479c92676e1b /compilerplugins
parentba269f7294e2416659011cbb498a2c6b5f9d5199 (diff)
handle nullptr in various clang plugins
since we are using it so widely now, instead of NULL Change-Id: I990ff1334f657663e8791ab064d69e56636fe6e7
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/defaultparams.cxx19
-rw-r--r--compilerplugins/clang/overrideparam.cxx16
-rw-r--r--compilerplugins/clang/singlevalfields.cxx3
3 files changed, 33 insertions, 5 deletions
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<CXXNullPtrLiteralExpr>(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<CXXNullPtrLiteralExpr>(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<CXXNullPtrLiteralExpr>(arg)) {
+ return "0";
+ }
return "?";
}