[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 03:48:11 PDT 2024


================
@@ -3125,6 +3125,16 @@ bool AsmParser::parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated) {
     do {
       if (parseEscapedString(Data))
         return true;
+
+      // Warn about newline characters in parsed string like GAS.
+      size_t NewlinePos = -1;
+      size_t DataSize = Data.size();
+      const char *Start = getTok().getLoc().getPointer() - DataSize - 1;
+
+      while ((NewlinePos = Data.find('\n', NewlinePos + 1)) < DataSize)
+        Warning(SMLoc::getFromPointer(Start + NewlinePos),
----------------
s-barannikov wrote:

Ideally, you wold want to check what `Warning` returns. It can return `true` in --fatal-warning mode, in which case compilation should fail.


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


More information about the llvm-commits mailing list