]> granicus.if.org Git - clang/commitdiff
Some refactoring of my ms_struct patch.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 27 Apr 2011 17:14:21 +0000 (17:14 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 27 Apr 2011 17:14:21 +0000 (17:14 +0000)
// rdar://8823265 related.

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

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/AST/RecordLayoutBuilder.cpp
lib/CodeGen/CGRecordLayoutBuilder.cpp

index 959e158cebcf5d02ceb384a43604a716f92d0b7d..9c3cfe73b2fd34748c0e4c921ebbf6256ddbc849 100644 (file)
@@ -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;
index e49bde3487ebe41b2c9800559c5997b4b8ee68e4..c571c559bc66e7032dd3ad74dae04cee0d5c8bbf 100644 (file)
@@ -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
index c4a156fbccf082f4bb259dbbbc79d7f0e46d81c3..407655770dfc39c856d1262dd73e78e7e7d318a5 100644 (file)
@@ -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);
index d202b6e825ec550990dfbb7879d2e5a87dd8f728..3d9fd88613b793cf898c50639ab7ba2bb92ba506 100644 (file)
@@ -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;
       }