[cfe-commits] r130851 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/AST/RecordLayoutBuilder.cpp test/CodeGen/ms_struct.c
Fariborz Jahanian
fjahanian at apple.com
Wed May 4 11:51:37 PDT 2011
Author: fjahanian
Date: Wed May 4 13:51:37 2011
New Revision: 130851
URL: http://llvm.org/viewvc/llvm-project?rev=130851&view=rev
Log:
More ms_struct bitfield stuff:
Adjacent bit fields are packed into the same 1-, 2-, or
4-byte allocation unit if the integral types are the same
size. // rdar://8823265.
Added:
cfe/trunk/test/CodeGen/ms_struct.c
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=130851&r1=130850&r2=130851&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed May 4 13:51:37 2011
@@ -406,6 +406,11 @@
/// bitfield which follows the bitfield 'LastFD'.
bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD,
const FieldDecl *LastFD) const;
+
+ /// BitfieldFollowsBitfield - return 'true" if 'FD' is a
+ /// bitfield which follows the bitfield 'LastFD'.
+ bool BitfieldFollowsBitfield(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;
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=130851&r1=130850&r2=130851&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed May 4 13:51:37 2011
@@ -551,6 +551,13 @@
}
+bool ASTContext::BitfieldFollowsBitfield(const FieldDecl *FD,
+ const FieldDecl *LastFD) const {
+ return (FD->isBitField() && LastFD && LastFD->isBitField() &&
+ FD->getBitWidth()-> EvaluateAsInt(*this).getZExtValue() &&
+ LastFD->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
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=130851&r1=130850&r2=130851&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed May 4 13:51:37 2011
@@ -1269,6 +1269,31 @@
// ignored:
else if (Context.ZeroBitfieldFollowsNonBitfield(FD, LastFD))
continue;
+ else if (Context.BitfieldFollowsBitfield(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.
+ std::pair<uint64_t, unsigned> FieldInfo =
+ Context.getTypeInfo(FD->getType());
+ uint64_t TypeSize = FieldInfo.first;
+ unsigned FieldAlign = FieldInfo.second;
+ FieldInfo = Context.getTypeInfo(LastFD->getType());
+ uint64_t TypeSizeLastFD = FieldInfo.first;
+ unsigned FieldAlignLastFD = FieldInfo.second;
+ if (TypeSizeLastFD != TypeSize) {
+ uint64_t UnpaddedFieldOffset =
+ getDataSizeInBits() - UnfilledBitsInLastByte;
+ FieldAlign = std::max(FieldAlign, FieldAlignLastFD);
+ uint64_t NewSizeInBits =
+ llvm::RoundUpToAlignment(UnpaddedFieldOffset, FieldAlign);
+ setDataSize(llvm::RoundUpToAlignment(NewSizeInBits,
+ Context.Target.getCharAlign()));
+ UnfilledBitsInLastByte = getDataSizeInBits() - NewSizeInBits;
+ setSize(std::max(getSizeInBits(), getDataSizeInBits()));
+ }
+ }
LastFD = FD;
}
LayoutField(*Field);
@@ -1480,7 +1505,7 @@
ZeroLengthBitfield = 0;
}
- if (Context.getLangOptions().MSBitfields) {
+ if (Context.getLangOptions().MSBitfields || 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.
Added: cfe/trunk/test/CodeGen/ms_struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms_struct.c?rev=130851&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/ms_struct.c (added)
+++ cfe/trunk/test/CodeGen/ms_struct.c Wed May 4 13:51:37 2011
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
+
+#define ATTR __attribute__((__ms_struct__))
+struct s1 {
+ int f32;
+ long long f64;
+} ATTR s1;
+
+// CHECK: %struct.s1 = type { i32, [4 x i8], i64 }
+
+struct s2 {
+ int f32;
+ long long f64[4];
+} ATTR s2;
+
+// CHECK: %struct.s2 = type { i32, [4 x i8], [4 x i64] }
+
+struct s3 {
+ int f32;
+ struct s1 s;
+} ATTR s3;
+
+// CHECK: %struct.s3 = type { i32, [4 x i8], %struct.s1 }
More information about the cfe-commits
mailing list