[cfe-commits] r77205 - in /cfe/trunk: lib/CodeGen/CodeGenTypes.cpp test/CodeGenCXX/class-layout.cpp
Anders Carlsson
andersca at mac.com
Mon Jul 27 10:10:56 PDT 2009
Author: andersca
Date: Mon Jul 27 12:10:54 2009
New Revision: 77205
URL: http://llvm.org/viewvc/llvm-project?rev=77205&view=rev
Log:
Use the CGRecordLayoutBuilder even if there are no fields, because in C++ an empty class will have a padding byte.
Added:
cfe/trunk/test/CodeGenCXX/class-layout.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=77205&r1=77204&r2=77205&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Mon Jul 27 12:10:54 2009
@@ -453,36 +453,27 @@
const llvm::Type *ResultType;
const RecordDecl *RD = cast<const RecordDecl>(TD);
- // There isn't any extra information for empty structures/unions.
- if (RD->field_empty()) {
- ResultType = llvm::StructType::get(std::vector<const llvm::Type*>());
- } else {
- // Layout fields.
- CGRecordLayout *Layout =
- CGRecordLayoutBuilder::ComputeLayout(*this, RD);
+ // Layout fields.
+ CGRecordLayout *Layout =
+ CGRecordLayoutBuilder::ComputeLayout(*this, RD);
- if (!Layout) {
- // Layout fields.
- RecordOrganizer RO(*this, *RD);
-
- if (TD->isStruct() || TD->isClass())
- RO.layoutStructFields(Context.getASTRecordLayout(RD));
- else {
- assert(TD->isUnion() && "unknown tag decl kind!");
- RO.layoutUnionFields(Context.getASTRecordLayout(RD));
- }
-
- Layout = new CGRecordLayout(RO.getLLVMType(),
- RO.getPaddingFields());
+ if (!Layout) {
+ // Layout fields.
+ RecordOrganizer RO(*this, *RD);
+
+ if (TD->isStruct() || TD->isClass())
+ RO.layoutStructFields(Context.getASTRecordLayout(RD));
+ else {
+ assert(TD->isUnion() && "unknown tag decl kind!");
+ RO.layoutUnionFields(Context.getASTRecordLayout(RD));
}
-
- // Get llvm::StructType.
- const Type *Key =
- Context.getTagDeclType(const_cast<TagDecl*>(TD)).getTypePtr();
-
- CGRecordLayouts[Key] = Layout;
- ResultType = Layout->getLLVMType();
+
+ Layout = new CGRecordLayout(RO.getLLVMType(),
+ RO.getPaddingFields());
}
+
+ CGRecordLayouts[Key] = Layout;
+ ResultType = Layout->getLLVMType();
// Refine our Opaque type to ResultType. This can invalidate ResultType, so
// make sure to read the result out of the holder.
Added: cfe/trunk/test/CodeGenCXX/class-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/class-layout.cpp?rev=77205&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/class-layout.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/class-layout.cpp Mon Jul 27 12:10:54 2009
@@ -0,0 +1,5 @@
+// RUN: clang-cc %s -emit-llvm -o %t &&
+
+// An extra byte shoudl be allocated for an empty class.
+// RUN: grep '%.truct.A = type { i8 }' %t
+struct A { } a;
More information about the cfe-commits
mailing list