From b6418ca5c38e03284f93f6bd4f5594e9fab123f3 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 16 May 2016 22:52:23 +0000 Subject: [PATCH] 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 --- lib/AST/Stmt.cpp | 23 +++++++++++++++-------- 1 file 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&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&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&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); -- 2.40.0