From: David Majnemer Date: Sun, 28 Dec 2014 07:42:49 +0000 (+0000) Subject: Lex: Don't let annotation tokens get into macro expansion X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=150e296459c5dab146545ec8bec6066718eaad67;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224896 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index b9461c1a83..93cc7c2978 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -332,7 +332,7 @@ def warn_cxx98_compat_variadic_macro : Warning< InGroup, DefaultIgnore; def ext_named_variadic_macro : Extension< "named variadic macros are a GNU extension">, InGroup; -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">, diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 8f610b4e5d..bf0ce72f66 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -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: diff --git a/test/Preprocessor/macro_arg_directive.c b/test/Preprocessor/macro_arg_directive.c index 5bc2236f0c..21d1b20acf 100644 --- a/test/Preprocessor/macro_arg_directive.c +++ b/test/Preprocessor/macro_arg_directive.c @@ -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(...) \