r272628 - [Parser] Handle __pragma(pack, etc. after type definitions

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 20:20:29 PDT 2016


Author: majnemer
Date: Mon Jun 13 22:20:28 2016
New Revision: 272628

URL: http://llvm.org/viewvc/llvm-project?rev=272628&view=rev
Log:
[Parser] Handle __pragma(pack, etc. after type definitions

Support certain MS pragmas right after the closing curly brace of a
class.  Clang did not expect __pragma in this position.

This fixes PR28094.

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/Parser/pragma-pack.c

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=272628&r1=272627&r2=272628&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jun 13 22:20:28 2016
@@ -3453,6 +3453,22 @@ void Parser::ParseDeclarationSpecifiers(
       ParseDecltypeSpecifier(DS);
       continue;
 
+    case tok::annot_pragma_pack:
+      HandlePragmaPack();
+      continue;
+
+    case tok::annot_pragma_ms_pragma:
+      HandlePragmaMSPragma();
+      continue;
+
+    case tok::annot_pragma_ms_vtordisp:
+      HandlePragmaMSVtorDisp();
+      continue;
+
+    case tok::annot_pragma_ms_pointers_to_members:
+      HandlePragmaMSPointersToMembers();
+      continue;
+
     case tok::kw___underlying_type:
       ParseUnderlyingTypeSpecifier(DS);
       continue;

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=272628&r1=272627&r2=272628&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Jun 13 22:20:28 2016
@@ -1100,6 +1100,13 @@ bool Parser::isValidAfterTypeSpecifier(b
   // FIXME: we should emit semantic diagnostic when declaration
   // attribute is in type attribute position.
   case tok::kw___attribute:     // struct foo __attribute__((used)) x;
+  case tok::annot_pragma_pack:  // struct foo {...} _Pragma(pack(pop));
+  // struct foo {...} _Pragma(section(...));
+  case tok::annot_pragma_ms_pragma:
+  // struct foo {...} _Pragma(vtordisp(pop));
+  case tok::annot_pragma_ms_vtordisp:
+  // struct foo {...} _Pragma(pointers_to_members(...));
+  case tok::annot_pragma_ms_pointers_to_members:
     return true;
   case tok::colon:
     return CouldBeBitfield;     // enum E { ... }   :         2;

Modified: cfe/trunk/test/Parser/pragma-pack.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/pragma-pack.c?rev=272628&r1=272627&r2=272628&view=diff
==============================================================================
--- cfe/trunk/test/Parser/pragma-pack.c (original)
+++ cfe/trunk/test/Parser/pragma-pack.c Mon Jun 13 22:20:28 2016
@@ -44,3 +44,7 @@ struct S
 #pragma pack()
   int e;
 };
+
+_Pragma("pack(push, 1)") struct PR28094 {
+  int a;
+} _Pragma("pack(pop)");




More information about the cfe-commits mailing list