compilerplugins/clang/constantparam.cxx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
New commits: commit 7a2c36bb69970f20b4896472e2d5a4e41df95b39 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Mar 23 15:35:17 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Mar 24 08:39:48 2022 +0100 loplugin:constantparam improvements (1) sanitize call value output, make downstream processing easier (2) remove bad ignoreLocation() call, which was eliminating a lot of valueable data and thus generating false positives Change-Id: I39230c260c5cf717559300913fbc68bc3485b957 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131986 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index f9f87b361bc5..5fd472954a9a 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -111,8 +111,6 @@ 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; @@ -122,7 +120,6 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde return; filename = filename.substr(strlen(SRCDIR)+1); - MyCallSiteInfo aInfo; aInfo.returnType = functionDecl->getReturnType().getCanonicalType().getAsString(); @@ -148,8 +145,8 @@ 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.callValue = callValue; aInfo.sourceLocation = filename.str() + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc)); loplugin::normalizeDotDotInFilePath(aInfo.sourceLocation); @@ -207,10 +204,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()")