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>
This commit is contained in:
Stephan Bergmann
2019-10-23 17:53:43 +02:00
parent 6facd4811a
commit 754e2d9be1

View File

@@ -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");
}