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

David Majnemer david.majnemer at gmail.com
Sat Dec 27 23:42:50 PST 2014


Author: majnemer
Date: Sun Dec 28 01:42:49 2014
New Revision: 224896

URL: http://llvm.org/viewvc/llvm-project?rev=224896&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Preprocessor/macro_arg_directive.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=224896&r1=224895&r2=224896&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Sun Dec 28 01:42:49 2014
@@ -332,7 +332,7 @@ def warn_cxx98_compat_variadic_macro : W
   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">,

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=224896&r1=224895&r2=224896&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Dec 28 01:42:49 2014
@@ -798,7 +798,8 @@ void Preprocessor::HandleDirective(Token
       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:

Modified: cfe/trunk/test/Preprocessor/macro_arg_directive.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_arg_directive.c?rev=224896&r1=224895&r2=224896&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_arg_directive.c (original)
+++ cfe/trunk/test/Preprocessor/macro_arg_directive.c Sun Dec 28 01:42:49 2014
@@ -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(...) \





More information about the cfe-commits mailing list