Browse Source

Some refactoring of my ms_struct patch.
// rdar://8823265 related.


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

Fariborz Jahanian 14 years ago
parent
commit
14d56ef43f

+ 5 - 0
include/clang/AST/ASTContext.h

@@ -394,6 +394,11 @@ public:
   FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
 
   void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
+  
+  /// ZeroBitfieldFollowsNonBitfield - return 'true" if 'FD' is a zero-length
+  /// bitfield which follows the non-bitfield 'LastFD'.
+  bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 
+                                      const FieldDecl *LastFD) const;
 
   // Access to the set of methods overridden by the given C++ method.
   typedef CXXMethodVector::iterator overridden_cxx_method_iterator;

+ 7 - 0
lib/AST/ASTContext.cpp

@@ -536,6 +536,13 @@ void ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst,
   InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl;
 }
 
+bool ASTContext::ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 
+                                    const FieldDecl *LastFD) const {
+  return (FD->isBitField() && LastFD && !LastFD->isBitField() &&
+          FD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue() == 0);
+  
+}
+
 ASTContext::overridden_cxx_method_iterator
 ASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const {
   llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos

+ 1 - 3
lib/AST/RecordLayoutBuilder.cpp

@@ -1261,10 +1261,8 @@ void RecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
       // Zero-length bitfields following non-bitfield members are
       // ignored:
       const FieldDecl *FD =  (*Field);
-      if (FD->isBitField() && LastFD && !LastFD->isBitField() &&
-          FD->getBitWidth()->EvaluateAsInt(Context).getZExtValue() == 0) {
+      if (Context.ZeroBitfieldFollowsNonBitfield(FD, LastFD))
         continue;
-      }
       LastFD = FD;
     }
     LayoutField(*Field);

+ 2 - 7
lib/CodeGen/CGRecordLayoutBuilder.cpp

@@ -753,10 +753,7 @@ bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
       // Zero-length bitfields following non-bitfield members are
       // ignored:
       const FieldDecl *FD =  (*Field);
-      // FIXME. Refactor into common code as it is used in several places.
-      if (FD->isBitField() && LastFD && !LastFD->isBitField() &&
-          FD->getBitWidth()->
-            EvaluateAsInt(Types.getContext()).getZExtValue() == 0) {
+      if (Types.getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) {
         --FieldNo;
         continue;
       }
@@ -999,9 +996,7 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) {
     if (IsMsStruct) {
       // Zero-length bitfields following non-bitfield members are
       // ignored:
-      if (FD->isBitField() && LastFD && !LastFD->isBitField() &&
-          FD->getBitWidth()->
-          EvaluateAsInt(getContext()).getZExtValue() == 0) {
+      if (getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) {
         --i;
         continue;
       }