diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index e0b10fa87c2c..7d8f21394c52 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -191,6 +191,8 @@ def err_label_end_of_compound_statement : Error< def err_address_of_label_outside_fn : Error< "use of address-of-label extension outside of a function body">; def err_expected_string_literal : Error<"expected string literal">; +def err_asm_operand_wide_string_literal : Error< + "cannot use wide string literal in 'asm'">; def err_expected_asm_operand : Error< "expected string literal or '[' for asm operand">, CatInlineAsm; def err_expected_selector_for_method : Error< diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index eb6dc443c9df..e74c46e2fda1 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1104,16 +1104,23 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { /// string-literal /// Parser::ExprResult Parser::ParseAsmStringLiteral() { - if (!isTokenStringLiteral()) { - Diag(Tok, diag::err_expected_string_literal); - return ExprError(); + switch (Tok.getKind()) { + case tok::string_literal: + break; + case tok::wide_string_literal: { + SourceLocation L = Tok.getLocation(); + Diag(Tok, diag::err_asm_operand_wide_string_literal) + << SourceRange(L, L); + return ExprError(); + } + default: + Diag(Tok, diag::err_expected_string_literal); + return ExprError(); } ExprResult Res(ParseStringLiteralExpression()); if (Res.isInvalid()) return move(Res); - // TODO: Diagnose: wide string literal in 'asm' - return move(Res); } diff --git a/clang/test/Parser/asm.c b/clang/test/Parser/asm.c index 90818261513f..23052c389eb2 100644 --- a/clang/test/Parser/asm.c +++ b/clang/test/Parser/asm.c @@ -14,3 +14,6 @@ void f2() { // rdar://5952468 __asm ; // expected-error {{expected '(' after 'asm'}} +// - Don't crash on wide string literals in 'asm'. +int foo asm (L"bar"); // expected-error {{cannot use wide string literal in 'asm'}} +