Commit Graph

16 Commits

Author SHA1 Message Date
David Majnemer bb51300970 CodeGen: Don't crash when initializing pointer-to-member fields in bases
Clang uses two types to talk about a C++ class, the
NonVirtualBaseLLVMType and the LLVMType.  Previously, we would allow one
of these to be packed and the other not.

This is problematic.  If both don't agree on a common subset of fields,
then routines like getLLVMFieldNo will point to the wrong field.  Solve
this by copying the 'packed'-ness of the complete type to the
non-virtual subobject.  For this to work, we need to take into account
the non-virtual subobject's size and alignment when we are computing the
layout of the complete object.

This fixes PR21089.

llvm-svn: 218577
2014-09-28 06:39:30 +00:00
Eli Bendersky 06a4042c8d Fix DOS-style newlines.
A previous patch r210330 (and possibly another) introduced DOS-style newlines
into a UNIX newline formatted file. 

Patch by Mark Heffernan (http://reviews.llvm.org/D4046)

llvm-svn: 210369
2014-06-06 20:31:48 +00:00
Warren Hunt f0ffdb2e60 Fixed Assert In CGRecordLowering
Prior to this patch, CGRecordLower assumed that virtual bases could not 
be placed before the nvsize of an object.  This isn't true in Itanium 
mode, virtual bases are placed at dsize rather than vnsize and in the 
case of zero sized non-virtual bases nvsize can be larger than dsize.  
This patch fixes CGRecordLowering to avoid an assert and to clip 
bitfields properly in this case.  A test case is included.

llvm-svn: 207280
2014-04-25 21:56:30 +00:00
Warren Hunt fb00c88703 Complete Rewrite of CGRecordLayoutBuilder
CGRecordLayoutBuilder was aging, complex, multi-pass, and shows signs of 
existing before ASTRecordLayoutBuilder.  It redundantly performed many 
layout operations that are now performed by ASTRecordLayoutBuilder and 
asserted that the results were the same.  With the addition of support 
for the MS-ABI, such as placement of vbptrs, vtordisps, different 
bitfield layout and a variety of other features, CGRecordLayoutBuilder 
was growing unwieldy in its redundancy.

This patch re-architects CGRecordLayoutBuilder to not perform any 
redundant layout but rather, as directly as possible, lower an 
ASTRecordLayout to an llvm::type.  The new architecture is significantly 
smaller and simpler than the CGRecordLayoutBuilder and contains fewer 
ABI-specific code paths.  It's also one pass.

The architecture of the new system is described in the comments. For the 
most part, the new system simply takes all of the fields and bases from 
an ASTRecordLayout, sorts them, inserts padding and dumps a record. 
Bitfields, unions and primary virtual bases make this process a bit more 
complicated.  See the inline comments.

In addition, this patch updates a few lit tests due to the fact that the 
new system computes more accurate llvm types than CGRecordLayoutBuilder. 
Each change is commented individually in the review.

Differential Revision: http://llvm-reviews.chandlerc.com/D2795

llvm-svn: 201907
2014-02-21 23:49:50 +00:00
Eli Friedman f927b8bc81 Add a missing check in CodeGen of packed classes with vtables. <rdar://problem/11324125>.
llvm-svn: 155689
2012-04-27 02:34:46 +00:00
John McCall 0710e551ef Record layout requires not just a definition, but a complete
definition.  Assert this.  Change IR generation to not try to
aggressively emit the IR translation of a record during its
own definition.  Fixes PR10912.

llvm-svn: 141350
2011-10-07 02:39:22 +00:00
Chris Lattner a5f58b05e8 clang side to match the LLVM IR type system rewrite patch.
llvm-svn: 134831
2011-07-09 17:41:47 +00:00
Anders Carlsson 02feb58dd7 Use the right type name.
llvm-svn: 129674
2011-04-17 21:57:29 +00:00
Anders Carlsson fcaaa697ec When laying out bases in, always try the "base subobject" LLVM type. If it
turns out that a field or base needs to be laid out in the tail padding of
the base, CGRecordLayoutBuilder::ResizeLastBaseFieldIfNecessary will convert
it to an array of i8.

I've audited the new test results to make sure that they are still valid. I've
also verified that we pass a self-host with this change.

This (finally) fixes PR5589!

llvm-svn: 129673
2011-04-17 21:56:13 +00:00
Anders Carlsson 0febb8acdf Put each test in class-layout.cpp into a separate namespace.
llvm-svn: 120925
2010-12-05 00:08:52 +00:00
Anders Carlsson 58fe1756fb Use a more appropriate LLVM type for the vtable pointer.
llvm-svn: 103078
2010-05-05 05:47:36 +00:00
Anders Carlsson d681a29ac0 Baby steps towards fixing PR5589. If a class needs a vtable pointer, add one.
llvm-svn: 91545
2009-12-16 17:27:20 +00:00
Daniel Dunbar 8fbe78f6fc Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.
- This is designed to make it obvious that %clang_cc1 is a "test variable"
   which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it
   can be useful to redefine what gets run as 'clang -cc1' (for example, to set
   a default target).

llvm-svn: 91446
2009-12-15 20:14:24 +00:00
Anders Carlsson 220bf4fc5a No need to add tail padding if the resulting LLVM struct type will have the same size as the final record size.
llvm-svn: 90820
2009-12-08 01:24:23 +00:00
Daniel Dunbar 8b57697954 Eliminate &&s in tests.
- 'for i in $(find . -type f); do sed -e 's#\(RUN:.*[^ ]\) *&& *$#\1#g' $i | FileUpdate $i; done', for the curious.

llvm-svn: 86430
2009-11-08 01:45:36 +00:00
Anders Carlsson cabdeb4932 Use the CGRecordLayoutBuilder even if there are no fields, because in C++ an empty class will have a padding byte.
llvm-svn: 77205
2009-07-27 17:10:54 +00:00