aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-04-26 17:54:40 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-04-26 17:54:40 +0000
commitc1a0a73c1fad684dd23e9aade02c4e00dbaeaee6 (patch)
tree212dc5afb8f8058e869f0b63e0f11d20f38e3883
parent8a285ae6fc4926cc4e419025eec63e2d6696e13f (diff)
Add ms_struct attribute on record typee
(and ignore it for now) - wip. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130224 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/Attr.td4
-rw-r--r--include/clang/Sema/AttributeList.h1
-rw-r--r--include/clang/Sema/Sema.h3
-rw-r--r--lib/Sema/AttributeList.cpp1
-rw-r--r--lib/Sema/SemaAttr.cpp6
-rw-r--r--lib/Sema/SemaDecl.cpp2
-rw-r--r--lib/Sema/SemaDeclAttr.cpp8
-rw-r--r--test/Sema/pragma-ms_struct.c15
8 files changed, 40 insertions, 0 deletions
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index 51ef7df47d..e4c6722e83 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -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">,
diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h
index e976865217..72cd47589f 100644
--- a/include/clang/Sema/AttributeList.h
+++ b/include/clang/Sema/AttributeList.h
@@ -235,6 +235,7 @@ public:
AT_weak_import,
AT_reqd_wg_size,
AT_init_priority,
+ AT_MsStruct,
IgnoredAttribute,
UnknownAttribute
};
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index e635526ebd..0e813a6e12 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -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();
diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp
index 983c0e0c28..619a5b961b 100644
--- a/lib/Sema/AttributeList.cpp
+++ b/lib/Sema/AttributeList.cpp
@@ -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);
}
diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp
index 7a50356fed..53dd297aeb 100644
--- a/lib/Sema/SemaAttr.cpp
+++ b/lib/Sema/SemaAttr.cpp
@@ -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) {
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 200f8ce037..6c25ddfca5 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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),
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 746c5dbb37..7f93ab72d6 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -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;
diff --git a/test/Sema/pragma-ms_struct.c b/test/Sema/pragma-ms_struct.c
index 61047c0309..b2c2684c61 100644
--- a/test/Sema/pragma-ms_struct.c
+++ b/test/Sema/pragma-ms_struct.c
@@ -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;
+
+