summaryrefslogtreecommitdiff
path: root/lib/AST/Stmt.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-05-16 22:52:23 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-05-16 22:52:23 +0000
commitb6418ca5c38e03284f93f6bd4f5594e9fab123f3 (patch)
tree7a27fc93d49d4f9b2e3bdc5ef14ce966aa8abc94 /lib/AST/Stmt.cpp
parent258d23689eb14c21c0a1e313ad7b43aefdb1f614 (diff)
Avoid O(n^2) string analysis when handling GNU __asm__ statements.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269716 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Stmt.cpp')
-rw-r--r--lib/AST/Stmt.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 7dfa3a9df1..f514ed21f4 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -503,6 +503,9 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
+ unsigned LastAsmStringToken = 0;
+ unsigned LastAsmStringOffset = 0;
+
while (1) {
// Done with the string?
if (CurPtr == StrEnd) {
@@ -589,10 +592,12 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
// (BeginLoc, EndLoc) represents the range of the operand we are currently
// processing. Unlike Str, the range includes the leading '%'.
- SourceLocation BeginLoc =
- getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
- SourceLocation EndLoc =
- getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI);
+ SourceLocation BeginLoc = getAsmString()->getLocationOfByte(
+ Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
+ &LastAsmStringOffset);
+ SourceLocation EndLoc = getAsmString()->getLocationOfByte(
+ CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken,
+ &LastAsmStringOffset);
Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
continue;
@@ -623,10 +628,12 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
// (BeginLoc, EndLoc) represents the range of the operand we are currently
// processing. Unlike Str, the range includes the leading '%'.
- SourceLocation BeginLoc =
- getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
- SourceLocation EndLoc =
- getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI);
+ SourceLocation BeginLoc = getAsmString()->getLocationOfByte(
+ Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
+ &LastAsmStringOffset);
+ SourceLocation EndLoc = getAsmString()->getLocationOfByte(
+ NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken,
+ &LastAsmStringOffset);
Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);