Skip to content

Commit 8ae39c8

Browse files
authored
[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.
1 parent 7eb8238 commit 8ae39c8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,11 @@ bool AsmParser::parseEscapedString(std::string &Data) {
30373037
StringRef Str = getTok().getStringContents();
30383038
for (unsigned i = 0, e = Str.size(); i != e; ++i) {
30393039
if (Str[i] != '\\') {
3040-
if (Str[i] == '\n') {
3040+
if ((Str[i] == '\n') || (Str[i] == '\r')) {
3041+
// Don't double-warn for Windows newlines.
3042+
if ((Str[i] == '\n') && (i > 0) && (Str[i - 1] == '\r'))
3043+
continue;
3044+
30413045
SMLoc NewlineLoc = SMLoc::getFromPointer(Str.data() + i);
30423046
if (Warning(NewlineLoc, "unterminated string; newline inserted"))
30433047
return true;

0 commit comments

Comments
 (0)