diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-10-23 17:53:43 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-10-23 22:09:38 +0200 |
commit | 754e2d9be1dd5ab1f8b231063c69abf916c49c56 (patch) | |
tree | 295638df0f5e9e4cde7fc76f6809630d9dcb0397 | |
parent | 6facd4811af68538544207fc1be606bf2cefbb1e (diff) |
Don't use broken StringAdd::getSourceAsString
it caused clang-cl to crash when processing desktop/source/app/opencl.cxx
Change-Id: I0a39697e75242cd00f12b60477d51a1e5bf96a4f
Reviewed-on: https://gerrit.libreoffice.org/81409
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/stringadd.cxx | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx index 1a9c7c90d152..67d3adc6c131 100644 --- a/compilerplugins/clang/stringadd.cxx +++ b/compilerplugins/clang/stringadd.cxx @@ -78,7 +78,6 @@ private: void checkForCompoundAssign(Stmt const* stmt1, Stmt const* stmt2, VarDecl const* varDecl); Expr const* ignore(Expr const*); - std::string getSourceAsString(SourceLocation startLoc, SourceLocation endLoc); bool isSideEffectFree(Expr const*); }; @@ -171,9 +170,8 @@ void StringAdd::checkForCompoundAssign(Stmt const* stmt1, Stmt const* stmt2, Var if (!isSideEffectFree(rhs)) return; // if we cross a #ifdef boundary - auto s - = getSourceAsString(stmt1->getSourceRange().getBegin(), stmt2->getSourceRange().getEnd()); - if (s.find("#if") != std::string::npos) + if (containsPreprocessingConditionalInclusion( + SourceRange(stmt1->getSourceRange().getBegin(), stmt2->getSourceRange().getEnd()))) return; report(DiagnosticsEngine::Warning, "simplify by merging with the preceding assignment", compat::getBeginLoc(stmt2)) @@ -314,18 +312,6 @@ bool StringAdd::isSideEffectFree(Expr const* expr) return false; } -std::string StringAdd::getSourceAsString(SourceLocation startLoc, SourceLocation endLoc) -{ - SourceManager& SM = compiler.getSourceManager(); - char const* p1 = SM.getCharacterData(startLoc); - char const* p2 = SM.getCharacterData(endLoc); - p2 += Lexer::MeasureTokenLength(endLoc, SM, compiler.getLangOpts()); - // sometimes we get weird results, probably from crossing internal LLVM buffer boundaries - if (p2 - p1 < 0) - return std::string(); - return std::string(p1, p2 - p1); -} - loplugin::Plugin::Registration<StringAdd> stringadd("stringadd"); } |