summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-05-09 12:14:32 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-05-09 13:52:30 +0200
commit12191a4f30078bb81c39a74a994ba7b2b410adaf (patch)
tree394626ae75e6b77e4159657847f894e4f7c9495b /compilerplugins
parent3a9854a92923df8013ca832c48aa9f284bcb1adc (diff)
make loplugin constantparam smarter about string params
Change-Id: Id3df69b38fd35f46735246a6d307a89aa10d4294 Reviewed-on: https://gerrit.libreoffice.org/37426 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/constantparam.cxx32
-rwxr-xr-xcompilerplugins/clang/constantparam.py4
2 files changed, 31 insertions, 5 deletions
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index 3f22324c60c2..b2d2ebd67395 100644
--- a/compilerplugins/clang/constantparam.cxx
+++ b/compilerplugins/clang/constantparam.cxx
@@ -14,6 +14,7 @@
#include "plugin.hxx"
#include "compat.hxx"
+#include "check.hxx"
/*
Find params on methods where the param is only ever passed as a single constant value.
@@ -59,6 +60,14 @@ public:
virtual void run() override
{
+ // ignore some files that make clang crash inside EvaluateAsInt
+ std::string fn( compiler.getSourceManager().getFileEntryForID(
+ compiler.getSourceManager().getMainFileID())->getName() );
+ normalizeDotDotInFilePath(fn);
+ if (fn == SRCDIR "/basegfx/source/matrix/b2dhommatrix.cxx"
+ || fn == SRCDIR "/basegfx/source/matrix/b3dhommatrix.cxx")
+ return;
+
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
// dump all our output in one write call - this is to try and limit IO "crosstalk" between multiple processes
@@ -169,10 +178,19 @@ std::string ConstantParam::getCallValue(const Expr* arg)
if (isa<MaterializeTemporaryExpr>(arg))
{
const CXXBindTemporaryExpr* strippedArg = dyn_cast_or_null<CXXBindTemporaryExpr>(arg->IgnoreParenCasts());
- if (strippedArg && isa<CXXTemporaryObjectExpr>(strippedArg->getSubExpr())
- && dyn_cast<CXXTemporaryObjectExpr>(strippedArg->getSubExpr())->getNumArgs() == 0)
+ if (strippedArg)
{
- return "defaultConstruct";
+ auto temp = dyn_cast<CXXTemporaryObjectExpr>(strippedArg->getSubExpr());
+ if (temp->getNumArgs() == 0)
+ {
+ if (loplugin::TypeCheck(temp->getType()).Class("OUString").Namespace("rtl").GlobalNamespace()) {
+ return "\"\"";
+ }
+ if (loplugin::TypeCheck(temp->getType()).Class("OString").Namespace("rtl").GlobalNamespace()) {
+ return "\"\"";
+ }
+ return "defaultConstruct";
+ }
}
}
@@ -192,6 +210,14 @@ std::string ConstantParam::getCallValue(const Expr* arg)
std::replace( s.begin(), s.end(), '\r', ' ');
std::replace( s.begin(), s.end(), '\n', ' ');
std::replace( s.begin(), s.end(), '\t', ' ');
+
+ // now normalize the value. For some params, like OUString, we can pass it as OUString() or "" and they are the same thing
+ if (s == "OUString()")
+ s = "\"\"";
+ else if (s == "OString()")
+ s = "\"\"";
+ else if (s == "aEmptyOUStr")
+ s = "\"\"";
return s;
}
diff --git a/compilerplugins/clang/constantparam.py b/compilerplugins/clang/constantparam.py
index fd299d85405b..99ef69c8816a 100755
--- a/compilerplugins/clang/constantparam.py
+++ b/compilerplugins/clang/constantparam.py
@@ -38,7 +38,7 @@ def RepresentsInt(s):
except ValueError:
return False
-consRegex = re.compile("^\w+\(\)$")
+constructor_regex = re.compile("^\w+\(\)$")
tmp1list = list()
tmp2list = list()
@@ -72,7 +72,7 @@ for callInfo, callValues in callDict.iteritems():
else:
tmp2list.append((sourceLoc, functionSig, callInfo[3] + " " + callInfo[2], callValue))
# look for places where the callsite is always a constructor invocation
- elif consRegex.match(callValue):
+ elif constructor_regex.match(callValue) or callValue == "\"\"":
if callValue.startswith("Get"): continue
if callValue.startswith("get"): continue
if "operator=" in functionSig: continue