Lex: Don't let annotation tokens get into macro expansion

We'd let annotation tokens from '#pragma pack' and the like get inside a
function-like macro.  This would lead to terror and mayhem; stop the
madness early.

This fixes PR22037.

llvm-svn: 224896
This commit is contained in:
David Majnemer 2014-12-28 07:42:49 +00:00
parent a894e9e070
commit f2d3bc0474
3 changed files with 8 additions and 2 deletions

View File

@ -332,7 +332,7 @@ def warn_cxx98_compat_variadic_macro : Warning<
InGroup<CXX98CompatPedantic>, DefaultIgnore;
def ext_named_variadic_macro : Extension<
"named variadic macros are a GNU extension">, InGroup<VariadicMacros>;
def err_embedded_include : Error<
def err_embedded_directive : Error<
"embedding a #%0 directive within macro arguments is not supported">;
def ext_embedded_directive : Extension<
"embedding a directive within macro arguments has undefined behavior">,

View File

@ -798,7 +798,8 @@ void Preprocessor::HandleDirective(Token &Result) {
case tok::pp_import:
case tok::pp_include_next:
case tok::pp___include_macros:
Diag(Result, diag::err_embedded_include) << II->getName();
case tok::pp_pragma:
Diag(Result, diag::err_embedded_directive) << II->getName();
DiscardUntilEndOfDirective();
return;
default:

View File

@ -7,6 +7,11 @@ a(n =
a);
_Static_assert(n == 5, "");
#define M(A)
M(
#pragma pack(pop) // expected-error {{embedding a #pragma directive within macro arguments is not supported}}
)
// header1.h
void fail(const char *);
#define MUNCH(...) \