Skip to content

Commit af41795

Browse files
committed
[MC,ELF] Emit warning if a string constant contains newline char.
GAS emits warning about newline in the string constant so make the same behaviour.
1 parent 915372a commit af41795

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/MC/MCParser/AsmLexer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Support/Compiler.h"
2222
#include "llvm/Support/SMLoc.h"
2323
#include "llvm/Support/SaveAndRestore.h"
24+
#include "llvm/Support/raw_ostream.h"
2425
#include <cassert>
2526
#include <cctype>
2627
#include <cstdio>
@@ -646,13 +647,17 @@ AsmToken AsmLexer::LexQuote() {
646647
return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
647648
}
648649

649-
// TODO: does gas allow multiline string constants?
650+
// gas doesn't allow multiline string constants
651+
// and emits a warning if a string constant contains newline character
650652
while (CurChar != '"') {
651653
if (CurChar == '\\') {
652654
// Allow \", etc.
653655
CurChar = getNextChar();
654656
}
655657

658+
if (CurChar == '\n')
659+
outs() << "Warning: unterminated string; newline inserted\n";
660+
656661
if (CurChar == EOF)
657662
return ReturnError(TokStart, "unterminated string constant");
658663

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t | FileCheck %s
2+
3+
.string "abcdefg
4+
12345678"
5+
6+
// CHECK: Warning: unterminated string; newline inserted

0 commit comments

Comments
 (0)