]> granicus.if.org Git - clang/commitdiff
Establish a new alignment for an ms_struct bitfield following
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 6 May 2011 21:56:12 +0000 (21:56 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 6 May 2011 21:56:12 +0000 (21:56 +0000)
a non-bitfield if size of their types differ.

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

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/AST/RecordLayoutBuilder.cpp
test/CodeGen/ms_struct-bitfield-3.c [new file with mode: 0644]

index 060ac4b1cfdf6eb667d6267a4b90f7c1741b0552..55aca03fe5645a2ab6bd6d3471c443ef680c7214 100644 (file)
@@ -411,6 +411,16 @@ public:
   /// bitfield which follows the bitfield 'LastFD'.
   bool BitfieldFollowsBitfield(const FieldDecl *FD,
                                    const FieldDecl *LastFD) const;
+  
+  /// NoneBitfieldFollowsBitfield - return 'true" if 'FD' is not a
+  /// bitfield which follows the bitfield 'LastFD'.
+  bool NoneBitfieldFollowsBitfield(const FieldDecl *FD,
+                                   const FieldDecl *LastFD) const;
+  
+  /// BitfieldFollowsNoneBitfield - return 'true" if 'FD' is a
+  /// bitfield which follows the none bitfield 'LastFD'.
+  bool BitfieldFollowsNoneBitfield(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 07823e04081adeae3c618b3ceffd6ea460e6bb20..5271c90bb8908787326c85d5d7a27278726811b3 100644 (file)
@@ -558,6 +558,18 @@ bool ASTContext::BitfieldFollowsBitfield(const FieldDecl *FD,
           LastFD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue());  
 }
 
+bool ASTContext::NoneBitfieldFollowsBitfield(const FieldDecl *FD,
+                                         const FieldDecl *LastFD) const {
+  return (!FD->isBitField() && LastFD && LastFD->isBitField() &&
+          LastFD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue());  
+}
+
+bool ASTContext::BitfieldFollowsNoneBitfield(const FieldDecl *FD,
+                                             const FieldDecl *LastFD) const {
+  return (FD->isBitField() && LastFD && !LastFD->isBitField() &&
+          FD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue());  
+}
+
 ASTContext::overridden_cxx_method_iterator
 ASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const {
   llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos
index ae67c3b39454e8ef7cfbdde60b675d86ba28570d..49c3b5851098afc7b80aa98ee873f7fcecd122aa 100644 (file)
@@ -1269,12 +1269,15 @@ void RecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
       // ignored:
       else if (Context.ZeroBitfieldFollowsNonBitfield(FD, LastFD))
         continue;
-      else if (Context.BitfieldFollowsBitfield(FD, LastFD)) {
+      else if (Context.BitfieldFollowsBitfield(FD, LastFD) ||
+               Context.BitfieldFollowsNoneBitfield(FD, LastFD)) {
         // Adjacent bit fields are packed into the same 1-, 2-, or
         // 4-byte allocation unit if the integral types are the same
         // size and if the next bit field fits into the current
         // allocation unit without crossing the boundary imposed by the
         // common alignment requirements of the bit fields.
+        // Also, establish a new alignment for a bitfield following
+        // a non-bitfield if size of their types differ.
         std::pair<uint64_t, unsigned> FieldInfo = 
           Context.getTypeInfo(FD->getType());
         uint64_t TypeSize = FieldInfo.first;
diff --git a/test/CodeGen/ms_struct-bitfield-3.c b/test/CodeGen/ms_struct-bitfield-3.c
new file mode 100644 (file)
index 0000000..9678298
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -emit-llvm-only  -triple x86_64-apple-darwin9 %s
+// rdar://8823265
+
+#define ATTR __attribute__((__ms_struct__))
+
+struct _struct_0
+{
+  int  member_0   : 25 ;
+  short  member_1   : 6 ;
+  char  member_2   : 2 ;
+  unsigned  short  member_3   : 1 ;
+  unsigned  char  member_4   : 7 ;
+  short  member_5   : 16 ;
+  int  : 0 ;
+  char  member_7  ;
+
+} ATTR;
+
+typedef struct _struct_0 struct_0;
+
+#define size_struct_0 20
+
+struct_0 test_struct_0 = { 18557917, 17, 3, 0, 80, 6487, 93 };
+static int a[(size_struct_0 == sizeof (struct_0)) -1];