While we would correctly handle asm("foo") and reject asm(L"bar"), we
weren't careful to handle cases where an ascii literal could be
concatenated with a wide literal.
This fixes PR21822.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223992
91177308-0d34-0410-b5e6-
96231b3b80d8
// inline asm.
let CategoryName = "Inline Assembly Issue" in {
- def err_asm_wide_character : Error<"wide string is invalid in 'asm'">;
def err_asm_invalid_lvalue_in_output : Error<"invalid lvalue in asm output">;
def err_asm_invalid_output_constraint : Error<
"invalid output constraint '%0' in asm">;
/// string-literal
///
ExprResult Parser::ParseAsmStringLiteral() {
- switch (Tok.getKind()) {
- case tok::string_literal:
- break;
- case tok::utf8_string_literal:
- case tok::utf16_string_literal:
- case tok::utf32_string_literal:
- case tok::wide_string_literal: {
- SourceLocation L = Tok.getLocation();
+ if (!isTokenStringLiteral()) {
+ Diag(Tok, diag::err_expected_string_literal)
+ << /*Source='in...'*/0 << "'asm'";
+ return ExprError();
+ }
+
+ ExprResult AsmString(ParseStringLiteralExpression());
+ if (!AsmString.isInvalid()) {
+ const auto *SL = cast<StringLiteral>(AsmString.get());
+ if (!SL->isAscii()) {
Diag(Tok, diag::err_asm_operand_wide_string_literal)
- << (Tok.getKind() == tok::wide_string_literal)
- << SourceRange(L, L);
+ << SL->isWide()
+ << SL->getSourceRange();
return ExprError();
}
- default:
- Diag(Tok, diag::err_expected_string_literal)
- << /*Source='in...'*/0 << "'asm'";
- return ExprError();
}
-
- return ParseStringLiteralExpression();
+ return AsmString;
}
/// ParseSimpleAsm
SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
// The parser verifies that there is a string literal here.
- if (!AsmString->isAscii())
- return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character)
- << AsmString->getSourceRange());
+ assert(AsmString->isAscii());
for (unsigned i = 0; i != NumOutputs; i++) {
StringLiteral *Literal = Constraints[i];
- if (!Literal->isAscii())
- return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
- << Literal->getSourceRange());
+ assert(Literal->isAscii());
StringRef OutputName;
if (Names[i])
for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
StringLiteral *Literal = Constraints[i];
- if (!Literal->isAscii())
- return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
- << Literal->getSourceRange());
+ assert(Literal->isAscii());
StringRef InputName;
if (Names[i])
// Check that the clobbers are valid.
for (unsigned i = 0; i != NumClobbers; i++) {
StringLiteral *Literal = Clobbers[i];
- if (!Literal->isAscii())
- return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
- << Literal->getSourceRange());
+ assert(Literal->isAscii());
StringRef Clobber = Literal->getString();
int foo4 asm (u"bar4"); // expected-error {{cannot use unicode string literal in 'asm'}}
int foo5 asm (U"bar5"); // expected-error {{cannot use unicode string literal in 'asm'}}
int foo6 asm ("bar6"_x); // expected-error {{string literal with user-defined suffix cannot be used here}}
+int foo6 asm ("" L"bar7"); // expected-error {{cannot use wide string literal in 'asm'}}