[PATCH] D17709: [MSVC Compat] Support for '__unaligned' attribute in function declaration

Olga Chupina via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 29 03:38:04 PST 2016


olga.a.chupina created this revision.
olga.a.chupina added a reviewer: rnk.
olga.a.chupina added a subscriber: cfe-commits.

This patch supports using '__unaligned' attribute in function declaration:

struct UnalignedS {
  void foo(double) __unaligned { ; }
};

void bar(void (UnalignedS::*pf)(double)__unaligned);

http://reviews.llvm.org/D17709

Files:
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  test/SemaCXX/MicrosoftExtensions.cpp

Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -4808,7 +4808,9 @@
     case tok::kw___thiscall:
     case tok::kw___vectorcall:
     case tok::kw___unaligned:
-      if (AttrReqs & AR_DeclspecAttributesParsed) {
+      // Allow __unaligned in function definition after a parameter list
+      if ((AttrReqs & AR_DeclspecAttributesParsed) ||
+          (Tok.getKind() == tok::kw___unaligned)) {
         ParseMicrosoftTypeAttributes(DS.getAttributes());
         continue;
       }
Index: lib/Parse/ParseTentative.cpp
===================================================================
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1782,7 +1782,8 @@
     return TPResult::Error;
 
   // cv-qualifier-seq
-  while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict))
+  while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict,
+                     tok::kw___unaligned))
     ConsumeToken();
 
   // ref-qualifier[opt]
Index: test/SemaCXX/MicrosoftExtensions.cpp
===================================================================
--- test/SemaCXX/MicrosoftExtensions.cpp
+++ test/SemaCXX/MicrosoftExtensions.cpp
@@ -80,6 +80,10 @@
 // __unaligned handling
 typedef char __unaligned *aligned_type;
 typedef struct UnalignedTag { int f; } __unaligned *aligned_type2;
+struct UnalignedS {
+  void foo(double) __unaligned { ; }
+};
+void bar(void (UnalignedS::*pf)(double)__unaligned);
 
 
 template<typename T> void h1(T (__stdcall M::* const )()) { }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17709.49354.patch
Type: text/x-patch
Size: 1608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160229/4570247e/attachment.bin>


More information about the cfe-commits mailing list