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

Dmitriy Chestnykh via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 07:46:22 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);
----------------
chestnykh wrote:

Yes, it works, thanks

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


More information about the llvm-commits mailing list