diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-02-16 13:27:57 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-02-16 14:17:12 +0100 |
commit | 6476745ac9a8cfba649a702a1a14af4526b65072 (patch) | |
tree | 1ac75e6de42899fbd7c32883874cf993165c7990 | |
parent | 79d0f67f01f75bf80e80a814ff3397fcf7dd1599 (diff) |
Fix loplugin:conststringvar
...after abc0344a234567aee0edcb4523036758d966481d "convert conststringvar plugin
to shared infrastructre", causing errors like
> [C ] cppuhelper/source/findsofficepath.c
> Assertion failed: (Ctx.getLangOpts().CPlusPlus), function isCXX11ConstantExpr, file llvm/llvm-project/clang/lib/AST/ExprConstant.cpp, line 14567.
> Stack dump:
[...]
> 6 libsystem_c.dylib 0x00007fff7266ca1c abort + 120
> 7 libsystem_c.dylib 0x00007fff7266bcd6 err + 0
> 8 clang 0x000000010b857ca3 clang::Expr::isCXX11ConstantExpr(clang::ASTContext const&, clang::APValue*, clang::SourceLocation*) const (.cold.2) + 35
> 9 clang 0x0000000109f7497e clang::Expr::isCXX11ConstantExpr(clang::ASTContext const&, clang::APValue*, clang::SourceLocation*) const + 1022
> 10 plugin.so 0x00000001182741ab loplugin::SharedRecursiveASTVisitorBasic::VisitVarDecl(clang::VarDecl*) + 1051
[...]
> clang-11: error: clang frontend command failed due to signal (use -v to see invocation)
Change-Id: I18c37dba294b0effd85bead8aa6e5679f77502d9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88777
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/conststringvar.cxx | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/compilerplugins/clang/conststringvar.cxx b/compilerplugins/clang/conststringvar.cxx index c5e83722ac47..99cfb01c06f7 100644 --- a/compilerplugins/clang/conststringvar.cxx +++ b/compilerplugins/clang/conststringvar.cxx @@ -27,17 +27,24 @@ public: explicit ConstStringVar(loplugin::InstantiationData const & data): FilteringPlugin(data) {} + bool preRun() override { + return compiler.getLangOpts().CPlusPlus; + // clang::Expr::isCXX11ConstantExpr only works for C++ + } + + void postRun() override { + for (auto v: vars_) { + report( + DiagnosticsEngine::Warning, + "variable is only used as rvalue, should be const", + v->getLocation()) + << v->getSourceRange(); + } + } + void run() override { - if (compiler.getLangOpts().CPlusPlus) { - // clang::Expr::isCXX11ConstantExpr only works for C++ - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); - for (auto v: vars_) { - report( - DiagnosticsEngine::Warning, - "variable is only used as rvalue, should be const", - v->getLocation()) - << v->getSourceRange(); - } + if (preRun() && TraverseDecl(compiler.getASTContext().getTranslationUnitDecl())) { + postRun(); } } |