Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MC] Fix llvm-mc unterminated string constants warning for MacOS and Windows #112995

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dpaoliello
Copy link
Contributor

@dpaoliello dpaoliello commented Oct 18, 2024

#98060 introduced a warning for unterminated string constants, however it was only checking for \n which means that it wouldn't trigger for MacOS newlines (\r), and produced strange results on Windows (always blaming column 1) including having the associated test fail 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.

@llvmbot llvmbot added the mc Machine (object) code label Oct 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 18, 2024

@llvm/pr-subscribers-mc

Author: Daniel Paoliello (dpaoliello)

Changes

#98060 introduced a warning for unterminated string constants, however it was only checking for \n which means that it wouldn't trigger for MacOS newlines (\r), and produced strange results on Windows (always blaming column 1) including having the associated test fail 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.


Full diff: https://github.com/llvm/llvm-project/pull/112995.diff

1 Files Affected:

  • (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+5-1)
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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants