[llvm] 8ae39c8 - [MC] Fix llvm-mc unterminated string constants warning for Windows (#112995)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 10:02:22 PDT 2024
Author: Daniel Paoliello
Date: 2024-10-21T10:02:18-07:00
New Revision: 8ae39c8e34de2d24c46827b324c76bac845c18b0
URL: https://github.com/llvm/llvm-project/commit/8ae39c8e34de2d24c46827b324c76bac845c18b0
DIFF: https://github.com/llvm/llvm-project/commit/8ae39c8e34de2d24c46827b324c76bac845c18b0.diff
LOG: [MC] Fix llvm-mc unterminated string constants warning for Windows (#112995)
#98060 introduced a warning for unterminated string constants, however
it was only checking for `\n` which means that it produced strange
results on Windows (always blaming column 1) including having the
[associated test
fail](https://buildkite.com/llvm-project/github-pull-requests/builds/111277#0192a122-c5c9-4e4e-bc5b-7532fec99ae4)
if Git happened to use Windows newlines when creating the file.
This fix for this is to detect both `\r` and `\n`, but don't double-warn
for Windows newlines.
Added:
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 3f55d8a66bc2ce..4774e5112af535 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3037,7 +3037,11 @@ bool AsmParser::parseEscapedString(std::string &Data) {
StringRef Str = getTok().getStringContents();
for (unsigned i = 0, e = Str.size(); i != e; ++i) {
if (Str[i] != '\\') {
- if (Str[i] == '\n') {
+ if ((Str[i] == '\n') || (Str[i] == '\r')) {
+ // Don't double-warn for Windows newlines.
+ if ((Str[i] == '\n') && (i > 0) && (Str[i - 1] == '\r'))
+ continue;
+
SMLoc NewlineLoc = SMLoc::getFromPointer(Str.data() + i);
if (Warning(NewlineLoc, "unterminated string; newline inserted"))
return true;
More information about the llvm-commits
mailing list