summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-10-27 07:59:28 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-10-27 10:14:28 +0100
commitc070fac05fef41f788b53fe2c1f60519688a40b1 (patch)
tree9417c5d1011707a2a1388307dd8a6c5efd85d73d /compilerplugins
parent142dc93d9ad793e036baa5573aea31cb6f416f57 (diff)
Teach loplugin:toolslong about curl_easy_getinfo
...see a9266c39cc71c6f23bfcad4ff6d33ccac53b5e52 "loplugin:toolslong (--enable-online-update)" arguing that "the third argument to curl_easy_getinfo(..., CURLINFO_RESPONSE_CODE, ...) must be a pointer to long". Change-Id: I7c542595219d2387cf869953fe40faef2b41b44f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104857 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/toolslong.cxx44
1 files changed, 44 insertions, 0 deletions
diff --git a/compilerplugins/clang/toolslong.cxx b/compilerplugins/clang/toolslong.cxx
index 1f55fb76d1d6..094087911e6a 100644
--- a/compilerplugins/clang/toolslong.cxx
+++ b/compilerplugins/clang/toolslong.cxx
@@ -89,6 +89,8 @@ public:
bool WalkUpFromFunctionDecl(FunctionDecl const* decl);
bool VisitFunctionDecl(FunctionDecl const* decl);
+ bool VisitCallExpr(CallExpr const* expr);
+
private:
bool rewrite(SourceLocation location);
bool isExcludedFile(SourceLocation spellingLocation) const;
@@ -511,6 +513,48 @@ bool ToolsLong::VisitFunctionDecl(FunctionDecl const* decl)
return true;
}
+bool ToolsLong::VisitCallExpr(CallExpr const* expr)
+{
+ if (ignoreLocation(expr))
+ {
+ return true;
+ }
+ auto const d1 = expr->getDirectCallee();
+ if (d1 == nullptr || !loplugin::DeclCheck(d1).Function("curl_easy_getinfo").GlobalNamespace())
+ {
+ return true;
+ }
+ if (expr->getNumArgs() != 3)
+ {
+ return true;
+ }
+ //TODO: Check expr->getArg(1) is CURLINFO_RESPONSE_CODE
+ auto const e1 = dyn_cast<UnaryOperator>(expr->getArg(2)->IgnoreParenImpCasts());
+ if (e1 == nullptr || e1->getOpcode() != UO_AddrOf)
+ {
+ return true;
+ }
+ auto const e2 = dyn_cast<DeclRefExpr>(e1->getSubExpr()->IgnoreParenImpCasts());
+ if (e2 == nullptr)
+ {
+ return true;
+ }
+ auto const d2 = e2->getDecl();
+ if (auto const d3 = dyn_cast<ParmVarDecl>(d2))
+ {
+ parmVarDecls_.erase(d3);
+ }
+ else if (auto const d4 = dyn_cast<VarDecl>(d2))
+ {
+ varDecls_.erase(d4);
+ }
+ else if (auto const d5 = dyn_cast<FieldDecl>(d2))
+ {
+ fieldDecls_.erase(d5);
+ }
+ return true;
+}
+
bool ToolsLong::rewrite(SourceLocation location)
{
if (rewriter != nullptr)