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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 22:55:24 PDT 2024


================
@@ -0,0 +1,69 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s 2>&1 -o /dev/null | FileCheck -DFILE=%s --strict-whitespace %s --check-prefix=CHECK-WARN
+
+.string "abcd\xFFefg
+12345678"
+
+// CHECK-WARN:   warn-newline-in-escaped-string.s:[[#@LINE-3]]:21: warning: unterminated string; newline inserted
+// CHECK-WARN:  .string "abcd\xFFefg
+
+.ascii "some test ascii
+
+sequence
+with
+newlines\x0A
+"
+
+// CHECK-WARN:   [[#@LINE-7]]:24: warning: unterminated string; newline inserted
+// CHECK-WARN:  .ascii "some test ascii
+// CHECK-WARN:                         ^
+// CHECK-WARN:   [[#@LINE-9]]:1: warning: unterminated string; newline inserted
+// CHECK-WARN:   ^
+// CHECK-WARN:   [[#@LINE-10]]:9: warning: unterminated string; newline inserted
+// CHECK-WARN:   sequence
+// CHECK-WARN:           ^
+// CHECK-WARN:   [[#@LINE-12]]:5: warning: unterminated string; newline inserted
+// CHECK-WARN:   with
+// CHECK-WARN:        ^
+// CHECK-WARN:   [[#@LINE-14]]:13: warning: unterminated string; newline inserted
+// CHECK-WARN:   newlines\x0A
+// CHECK-WARN:           ^
+
+.asciz "another test string
+
+with
+newline characters
+
+
+"
+
+// CHECK-WARN:   [[#@LINE-8]]:28: warning: unterminated string; newline inserted
+// CHECK-WARN:   .asciz "another test string
+// CHECK-WARN:   [[#@LINE-9]]:1: warning: unterminated string; newline inserted
+// CHECK-WARN:   ^
----------------
MaskRay wrote:

You can delete `^` checks. With column numbers on the above line, `^` check isn't useful.

Use `-NEXT` whenever applicable

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


More information about the llvm-commits mailing list