]> granicus.if.org Git - clang/commitdiff
Add ms_struct attribute on record typee
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 26 Apr 2011 17:54:40 +0000 (17:54 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 26 Apr 2011 17:54:40 +0000 (17:54 +0000)
(and ignore it for now) - wip.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130224 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
include/clang/Sema/AttributeList.h
include/clang/Sema/Sema.h
lib/Sema/AttributeList.cpp
lib/Sema/SemaAttr.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclAttr.cpp
test/Sema/pragma-ms_struct.c

index 51ef7df47dc817022f25c4d00512129a84f63a2b..e4c6722e83789ad63b377bf8b0dedd028a43daca 100644 (file)
@@ -255,6 +255,10 @@ def Final : InheritableAttr {
   let Spellings = [];
 }
 
+def MsStruct : InheritableAttr {
+  let Spellings = ["__ms_struct__"];
+}
+
 def Format : InheritableAttr {
   let Spellings = ["format"];
   let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">,
index e976865217a72ed37918bcd8694d59887d934db1..72cd47589f9147a4d0bd12d8d371ae6a9002aeff 100644 (file)
@@ -235,6 +235,7 @@ public:
     AT_weak_import,
     AT_reqd_wg_size,
     AT_init_priority,
+    AT_MsStruct,
     IgnoredAttribute,
     UnknownAttribute
   };
index e635526ebdfdcadfbdf69920607434bcdcd28863..0e813a6e123f387f7ebc7a3153406dec5c77c83f 100644 (file)
@@ -4905,6 +4905,9 @@ public:
   /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
   void AddAlignmentAttributesForRecord(RecordDecl *RD);
 
+  /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
+  void AddMsStructLayoutForRecord(RecordDecl *RD);
+
   /// FreePackedContext - Deallocate and null out PackContext.
   void FreePackedContext();
 
index 983c0e0c289cf99f1bd48a15075efb85b91a41f2..619a5b961bfefe915509366446b8e8629e1d46e9 100644 (file)
@@ -202,5 +202,6 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
     .Case("opencl_kernel_function", AT_opencl_kernel_function)
     .Case("uuid", AT_uuid)
     .Case("pcs", AT_pcs)
+    .Case("ms_struct", AT_MsStruct)
     .Default(UnknownAttribute);
 }
index 7a50356fedbba0761192fabdb1b1621a0bd0611a..53dd297aebb3b6385cb5edeef3cff34c06637b5b 100644 (file)
@@ -129,6 +129,12 @@ void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
   }
 }
 
+void Sema::AddMsStructLayoutForRecord(RecordDecl *RD) {
+  if (!MSStructPragmaOn)
+    return;
+  RD->addAttr(::new (Context) MsStructAttr(SourceLocation(), Context));
+}
+
 void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
                                    SourceLocation PragmaLoc,
                                    SourceLocation KindLoc) {
index 200f8ce03792e7c94e393e43ee6a89633c62c464..6c25ddfca54b83414c0c7d5b643d523af445cef5 100644 (file)
@@ -7094,6 +7094,8 @@ CreateNewDecl:
     // the #pragma tokens are effectively skipped over during the
     // parsing of the struct).
     AddAlignmentAttributesForRecord(RD);
+    
+    AddMsStructLayoutForRecord(RD);
   }
 
   // If this is a specialization of a member class (of a class template),
index 746c5dbb37440bf507b526a1f98ee7a77ee70a38..7f93ab72d6d1c0903da82fa4e1289a8c4a964bd4 100644 (file)
@@ -261,6 +261,13 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
 }
 
+static void HandleMsStructAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+  if (TagDecl *TD = dyn_cast<TagDecl>(d))
+    TD->addAttr(::new (S.Context) MsStructAttr(Attr.getLoc(), S.Context));
+  else
+    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
+}
+
 static void HandleIBAction(Decl *d, const AttributeList &Attr, Sema &S) {
   // check the attribute arguments.
   if (Attr.getNumArgs() > 0) {
@@ -2890,6 +2897,7 @@ static void ProcessInheritableDeclAttr(Scope *scope, Decl *D,
       HandleInitPriorityAttr(D, Attr, S); break;
       
   case AttributeList::AT_packed:      HandlePackedAttr      (D, Attr, S); break;
+  case AttributeList::AT_MsStruct:    HandleMsStructAttr    (D, Attr, S); break;
   case AttributeList::AT_section:     HandleSectionAttr     (D, Attr, S); break;
   case AttributeList::AT_unavailable: HandleUnavailableAttr (D, Attr, S); break;
   case AttributeList::AT_unused:      HandleUnusedAttr      (D, Attr, S); break;
index 61047c03098fb733160851b93826c89b884ae6b4..b2c2684c619458d62ddde5da5ac76280eaff2198 100644 (file)
@@ -17,3 +17,18 @@ struct foo
   char c;
 };
 
+
+struct {
+                   unsigned long bf_1 : 12;
+                   unsigned long : 0;
+                   unsigned long bf_2 : 12;
+} __attribute__((__ms_struct__)) t1;
+
+struct S {
+                  double __attribute__((ms_struct)) d; // expected-warning {{'ms_struct' attribute ignored}}
+                   unsigned long bf_1 : 12;
+                   unsigned long : 0;
+                   unsigned long bf_2 : 12;
+} __attribute__((ms_struct)) t2;
+
+