summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/constantparam.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/constantparam.cxx')
-rw-r--r--compilerplugins/clang/constantparam.cxx36
1 files changed, 15 insertions, 21 deletions
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index da1ee7841ebe..fd8f8f4e7992 100644
--- a/compilerplugins/clang/constantparam.cxx
+++ b/compilerplugins/clang/constantparam.cxx
@@ -61,6 +61,8 @@ public:
virtual void run() override
{
+ handler.enableTreeWideAnalysisMode();
+
// ignore some files that make clang crash inside EvaluateAsInt
std::string fn(handler.getMainFileName());
loplugin::normalizeDotDotInFilePath(fn);
@@ -104,10 +106,6 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
{
if (functionDecl->getInstantiatedFromMemberFunction())
functionDecl = functionDecl->getInstantiatedFromMemberFunction();
-#if CLANG_VERSION < 90000
- else if (functionDecl->getClassScopeSpecializationPattern())
- functionDecl = functionDecl->getClassScopeSpecializationPattern();
-#endif
else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern();
@@ -115,18 +113,19 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
return;
if (functionDecl->isVariadic())
return;
- if (ignoreLocation(functionDecl))
- return;
// ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(functionDecl))
return;
+
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() );
- StringRef filename = getFilenameOfLocation(expansionLoc);
+ std::string filename = getFilenameOfLocation(expansionLoc).str();
+ loplugin::normalizeDotDotInFilePath(filename);
if (!loplugin::hasPathnamePrefix(filename, SRCDIR "/"))
return;
+ if (loplugin::hasPathnamePrefix(filename, WORKDIR "/"))
+ return;
filename = filename.substr(strlen(SRCDIR)+1);
-
MyCallSiteInfo aInfo;
aInfo.returnType = functionDecl->getReturnType().getCanonicalType().getAsString();
@@ -152,10 +151,9 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
aInfo.paramIndex = paramIndex;
if (paramIndex < (int)functionDecl->getNumParams())
aInfo.paramType = functionDecl->getParamDecl(paramIndex)->getType().getCanonicalType().getAsString();
- aInfo.callValue = callValue;
- aInfo.sourceLocation = filename.str() + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
- loplugin::normalizeDotDotInFilePath(aInfo.sourceLocation);
+ aInfo.callValue = callValue;
+ aInfo.sourceLocation = filename + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
callSet.insert(aInfo);
}
@@ -202,8 +200,8 @@ std::string ConstantParam::getCallValue(const Expr* arg)
// Get the expression contents.
// This helps us find params which are always initialised with something like "OUString()".
SourceManager& SM = compiler.getSourceManager();
- SourceLocation startLoc = compat::getBeginLoc(arg);
- SourceLocation endLoc = compat::getEndLoc(arg);
+ SourceLocation startLoc = arg->getBeginLoc();
+ SourceLocation endLoc = arg->getEndLoc();
const char *p1 = SM.getCharacterData( startLoc );
const char *p2 = SM.getCharacterData( endLoc );
if (!p1 || !p2 || (p2 - p1) < 0 || (p2 - p1) > 40) {
@@ -211,10 +209,10 @@ std::string ConstantParam::getCallValue(const Expr* arg)
}
unsigned n = Lexer::MeasureTokenLength( endLoc, SM, compiler.getLangOpts());
std::string s( p1, p2 - p1 + n);
- // strip linefeed and tab characters so they don't interfere with the parsing of the log file
- std::replace( s.begin(), s.end(), '\r', ' ');
- std::replace( s.begin(), s.end(), '\n', ' ');
- std::replace( s.begin(), s.end(), '\t', ' ');
+ // sanitize call value, makes using command line tools (and python) much less error prone
+ for (auto const & ch : s)
+ if (ch < 32)
+ return "sanitised";
// 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()")
@@ -249,10 +247,6 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) {
// work our way back to the root definition for template methods
if (functionDecl->getInstantiatedFromMemberFunction())
functionDecl = functionDecl->getInstantiatedFromMemberFunction();
-#if CLANG_VERSION < 90000
- else if (functionDecl->getClassScopeSpecializationPattern())
- functionDecl = functionDecl->getClassScopeSpecializationPattern();
-#endif
else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern();