Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp	(revision 165422)
+++ lib/Sema/SemaDeclAttr.cpp	(working copy)
@@ -974,8 +974,10 @@
 }
 
 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));
+    RD->setMsStruct(true);
+  }
   else
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
 }
Index: lib/Sema/SemaAttr.cpp
===================================================================
--- lib/Sema/SemaAttr.cpp	(revision 165422)
+++ lib/Sema/SemaAttr.cpp	(working copy)
@@ -133,6 +133,7 @@
   if (!MSStructPragmaOn)
     return;
   RD->addAttr(::new (Context) MsStructAttr(SourceLocation(), Context));
+  RD->setMsStruct(true);
 }
 
 void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
Index: lib/AST/Decl.cpp
===================================================================
--- lib/AST/Decl.cpp	(revision 165422)
+++ 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();
 
   for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
        I != E; ++I, ++Index) {
@@ -2725,6 +2725,8 @@
   AnonymousStructOrUnion = false;
   HasObjectMember = false;
   LoadedFieldsFromExternalStorage = false;
+  // This is an ms_struct by default if the -mms-bitfields option is present.
+  IsMsStruct = (getASTContext().getLangOpts().MSBitfields == 1);
   assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
 }
 
Index: lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- lib/AST/RecordLayoutBuilder.cpp	(revision 165422)
+++ 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();
+  }
 
-  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: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp	(revision 165422)
+++ lib/CodeGen/CGDebugInfo.cpp	(working copy)
@@ -824,7 +824,7 @@
       }
     }
   } else {
-    bool IsMsStruct = record->hasAttr<MsStructAttr>();
+    bool IsMsStruct = record->isMsStruct();
     const FieldDecl *LastFD = 0;
     for (RecordDecl::field_iterator I = record->field_begin(),
            E = record->field_end();
Index: lib/CodeGen/CGRecordLayoutBuilder.cpp
===================================================================
--- lib/CodeGen/CGRecordLayoutBuilder.cpp	(revision 165422)
+++ 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();
 
   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();
   for (unsigned i = 0, e = AST_RL.getFieldCount(); i != e; ++i, ++it) {
     const FieldDecl *FD = *it;
 
Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp	(revision 165422)
+++ 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();
   
   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();
   uint64_t OffsetBits = CGM.getContext().toBits(Offset);
 
   for (RecordDecl::field_iterator Field = RD->field_begin(),
Index: include/clang/AST/Decl.h
===================================================================
--- include/clang/AST/Decl.h	(revision 165422)
+++ include/clang/AST/Decl.h	(working copy)
@@ -2933,6 +2933,10 @@
   mutable bool LoadedFieldsFromExternalStorage : 1;
   friend class DeclContext;
 
+  /// IsMsStruct - Whether ms_struct is in effect or not. The -mms-bitfields option
+  /// will turn this on as well.
+  bool IsMsStruct : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
              SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3035,6 +3039,14 @@
     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 { return IsMsStruct; }
+
+  // Set whether or not this is an ms_struct.
+  void setMsStruct(bool value) { IsMsStruct = value; }
+
 private:
   /// \brief Deserialize just the fields.
   void LoadFieldsFromExternalStorage() const;
