diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
commit | 344a3780b2e33f6ca763666c380202b18aab72a3 (patch) | |
tree | f0b203ee6eb71d7fdd792373e3c81eb18d6934dd /lld/ELF/ScriptLexer.cpp | |
parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) | |
download | src-344a3780b2e33f6ca763666c380202b18aab72a3.tar.gz src-344a3780b2e33f6ca763666c380202b18aab72a3.zip |
Vendor import of llvm-project main 88e66fa60ae5, the last commit beforevendor/llvm-project/llvmorg-13-init-16847-g88e66fa60ae5vendor/llvm-project/llvmorg-12.0.1-rc2-0-ge7dac564cd0evendor/llvm-project/llvmorg-12.0.1-0-gfed41342a82f
the upstream release/13.x branch was created.
Diffstat (limited to 'lld/ELF/ScriptLexer.cpp')
-rw-r--r-- | lld/ELF/ScriptLexer.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp index 4b16974dd134..236a188324cd 100644 --- a/lld/ELF/ScriptLexer.cpp +++ b/lld/ELF/ScriptLexer.cpp @@ -56,7 +56,25 @@ size_t ScriptLexer::getLineNumber() { return 1; StringRef s = getCurrentMB().getBuffer(); StringRef tok = tokens[pos - 1]; - return s.substr(0, tok.data() - s.data()).count('\n') + 1; + const size_t tokOffset = tok.data() - s.data(); + + // For the first token, or when going backwards, start from the beginning of + // the buffer. If this token is after the previous token, start from the + // previous token. + size_t line = 1; + size_t start = 0; + if (lastLineNumberOffset > 0 && tokOffset >= lastLineNumberOffset) { + start = lastLineNumberOffset; + line = lastLineNumber; + } + + line += s.substr(start, tokOffset - start).count('\n'); + + // Store the line number of this token for reuse. + lastLineNumberOffset = tokOffset; + lastLineNumber = line; + + return line; } // Returns 0-based column number of the current token. |