Index: D:/projects/llvm/llvm/tools/clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- D:/projects/llvm/llvm/tools/clang/lib/Sema/SemaDeclAttr.cpp	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/lib/Sema/SemaDeclAttr.cpp	(working copy)
@@ -974,8 +974,8 @@
 }
 
 static void handleMsStructAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (TagDecl *TD = dyn_cast<TagDecl>(D))
-    TD->addAttr(::new (S.Context) MsStructAttr(Attr.getRange(), S.Context));
+  if (RecordDecl *RD = dyn_cast<RecordDecl>(D))
+    RD->addAttr(::new (S.Context) MsStructAttr(Attr.getRange(), S.Context));
   else
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
 }
Index: D:/projects/llvm/llvm/tools/clang/lib/AST/Decl.cpp
===================================================================
--- D:/projects/llvm/llvm/tools/clang/lib/AST/Decl.cpp	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/lib/AST/Decl.cpp	(working copy)
@@ -2514,7 +2514,7 @@
   unsigned Index = 0;
   const RecordDecl *RD = getParent();
   const FieldDecl *LastFD = 0;
-  bool IsMsStruct = RD->hasAttr<MsStructAttr>();
+  bool IsMsStruct = RD->isMsStruct(getASTContext());
 
   for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
        I != E; ++I, ++Index) {
@@ -2762,6 +2762,14 @@
   TagDecl::completeDefinition();
 }
 
+/// isMsStrust - Get whether or not this is an ms_struct which can
+/// be turned on with an attribute, pragma, or -mms-bitfields
+/// commandline option.
+bool RecordDecl::isMsStruct(const ASTContext &C) const { 
+  return hasAttr<MsStructAttr>() || 
+    (C.getLangOpts().MSBitfields == 1);
+}
+
 static bool isFieldOrIndirectField(Decl::Kind K) {
   return FieldDecl::classofKind(K) || IndirectFieldDecl::classofKind(K);
 }
Index: D:/projects/llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- D:/projects/llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp	(working copy)
@@ -1574,12 +1574,12 @@
 }
 
 void RecordLayoutBuilder::InitializeLayout(const Decl *D) {
-  if (const RecordDecl *RD = dyn_cast<RecordDecl>(D))
+  if (const RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
     IsUnion = RD->isUnion();
+    IsMsStruct = RD->isMsStruct(Context);
+  }
 
-  Packed = D->hasAttr<PackedAttr>();
-  
-  IsMsStruct = D->hasAttr<MsStructAttr>();
+  Packed = D->hasAttr<PackedAttr>();  
 
   // Honor the default struct packing maximum alignment flag.
   if (unsigned DefaultMaxFieldAlignment = Context.getLangOpts().PackStruct) {
@@ -2085,7 +2085,7 @@
       ZeroLengthBitfield = 0;
     }
 
-    if (Context.getLangOpts().MSBitfields || IsMsStruct) {
+    if (IsMsStruct) {
       // If MS bitfield layout is required, figure out what type is being
       // laid out and align the field to the width of that type.
       
Index: D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp	(working copy)
@@ -824,7 +824,7 @@
       }
     }
   } else {
-    bool IsMsStruct = record->hasAttr<MsStructAttr>();
+    bool IsMsStruct = record->isMsStruct(CGM.getContext());
     const FieldDecl *LastFD = 0;
     for (RecordDecl::field_iterator I = record->field_begin(),
            E = record->field_end();
Index: D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===================================================================
--- D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp	(working copy)
@@ -206,7 +206,7 @@
   Alignment = Types.getContext().getASTRecordLayout(D).getAlignment();
   Packed = D->hasAttr<PackedAttr>();
   
-  IsMsStruct = D->hasAttr<MsStructAttr>();
+  IsMsStruct = D->isMsStruct(Types.getContext());
 
   if (D->isUnion()) {
     LayoutUnion(D);
@@ -1061,7 +1061,7 @@
   const ASTRecordLayout &AST_RL = getContext().getASTRecordLayout(D);
   RecordDecl::field_iterator it = D->field_begin();
   const FieldDecl *LastFD = 0;
-  bool IsMsStruct = D->hasAttr<MsStructAttr>();
+  bool IsMsStruct = D->isMsStruct(getContext());
   for (unsigned i = 0, e = AST_RL.getFieldCount(); i != e; ++i, ++it) {
     const FieldDecl *FD = *it;
 
Index: D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/lib/CodeGen/CGExprConstant.cpp	(working copy)
@@ -379,7 +379,7 @@
   unsigned FieldNo = 0;
   unsigned ElementNo = 0;
   const FieldDecl *LastFD = 0;
-  bool IsMsStruct = RD->hasAttr<MsStructAttr>();
+  bool IsMsStruct = RD->isMsStruct(CGM.getContext());
   
   for (RecordDecl::field_iterator Field = RD->field_begin(),
        FieldEnd = RD->field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
@@ -478,7 +478,7 @@
 
   unsigned FieldNo = 0;
   const FieldDecl *LastFD = 0;
-  bool IsMsStruct = RD->hasAttr<MsStructAttr>();
+  bool IsMsStruct = RD->isMsStruct(CGM.getContext());
   uint64_t OffsetBits = CGM.getContext().toBits(Offset);
 
   for (RecordDecl::field_iterator Field = RD->field_begin(),
Index: D:/projects/llvm/llvm/tools/clang/test/CodeGen/mms-bitfields-1.c
===================================================================
--- D:/projects/llvm/llvm/tools/clang/test/CodeGen/mms-bitfields-1.c	(revision 0)
+++ D:/projects/llvm/llvm/tools/clang/test/CodeGen/mms-bitfields-1.c	(working copy)
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -D TEST=1 -mms-bitfields -emit-llvm-only -triple i386-apple-darwin10 %s
+// RUN: %clang_cc1 -D TEST=2 -emit-llvm-only -triple i386-apple-darwin10 %s
+// RUN: %clang_cc1 -D TEST=3 -emit-llvm-only -triple i386-apple-darwin10 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin10 %s
+
+#if (TEST == 2)
+   // -mms-bitfields should behave the same as __attribute__((ms_struct))
+   #define MS_STRUCT __attribute__((ms_struct))
+#else
+   #define MS_STRUCT
+#endif
+
+struct
+{
+   int a : 1;
+   short b : 1;
+} MS_STRUCT t1;
+
+#if (TEST == 1) || (TEST == 2)
+   // MS pads out bitfields between different types.
+   static int arr1[(sizeof(t1) == 8) -1];
+#else
+   // Not using MS bitfields.
+   static int arr1[(sizeof(t1) == 4) -1];
+#endif
+
+enum
+{
+   A = 0,
+   B,
+   C
+} __attribute__((ms_struct)) e1; // expected-warning {{'ms_struct' attribute ignored}}
+
+int main() {
+  return 0;
+}
\ No newline at end of file
Index: D:/projects/llvm/llvm/tools/clang/include/clang/AST/Decl.h
===================================================================
--- D:/projects/llvm/llvm/tools/clang/include/clang/AST/Decl.h	(revision 165422)
+++ D:/projects/llvm/llvm/tools/clang/include/clang/AST/Decl.h	(working copy)
@@ -3035,6 +3035,11 @@
     return K >= firstRecord && K <= lastRecord;
   }
 
+  /// isMsStrust - Get whether or not this is an ms_struct which can
+  /// be turned on with an attribute, pragma, or -mms-bitfields
+  /// commandline option.
+  bool isMsStruct(const ASTContext &C) const;
+
 private:
   /// \brief Deserialize just the fields.
   void LoadFieldsFromExternalStorage() const;
