[llvm] [MC,ELF] Emit warning if a string constant contains newline char. (PR #98060)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 06:53:15 PDT 2024


================
@@ -3021,14 +3021,20 @@ bool AsmParser::parseDirectiveSet(StringRef IDVal, AssignmentKind Kind) {
   return false;
 }
 
-bool AsmParser::parseEscapedString(std::string &Data) {
+bool AsmParser::parseEscapedString(std::string &Data, bool WarnNewline) {
   if (check(getTok().isNot(AsmToken::String), "expected string"))
     return true;
 
   Data = "";
   StringRef Str = getTok().getStringContents();
   for (unsigned i = 0, e = Str.size(); i != e; ++i) {
     if (Str[i] != '\\') {
+      if (Str[i] == '\n' && WarnNewline) {
+        SMLoc NewlineLoc =
+            SMLoc::getFromPointer(getTok().getLoc().getPointer() + i + 1);
----------------
s-barannikov wrote:

I think you can reduce this to just the following, but need to check:
```suggestion
        SMLoc NewlineLoc = SMLoc::getFromPointer(Str.data() + i);
```


https://github.com/llvm/llvm-project/pull/98060


More information about the llvm-commits mailing list