Commit Graph

162 Commits

Author SHA1 Message Date
Aaron Ballman 445a939db8 [C++11] Replacing CXXRecordDecl iterators vbases_begin() and vbases_end() with iterator_range vbases(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203808
2014-03-13 16:15:17 +00:00
Aaron Ballman 574705ed7f [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with iterator_range bases(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203803
2014-03-13 15:41:46 +00:00
Aaron Ballman e8a8baef44 [C++11] Replacing RecordDecl iterators field_begin() and field_end() with iterator_range fields(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203355
2014-03-08 20:12:42 +00:00
Warren Hunt fed55979b1 Fixed an assertion failure related to bitfield lowering.
When lowering a bitfield, CGRecordLowering would assign the wrong 
storage type to a bitfield in some cases and trigger an assertion.  In 
these cases the layout was still correct, just the bitfield info was 
wrong.

llvm-svn: 202562
2014-03-01 00:38:40 +00:00
Reid Kleckner c497f1d487 PR18962: Fix "Unable to find record layout information for type"
Clang is using llvm::StructType::isOpaque() as a way of signaling if
we've finished record type conversion in
CodeGenTypes::isRecordLayoutComplete().  However, Clang was setting the
body of the type before it finished laying out the type as a base type.
Laying out the %class.C.base LLVM type attempts to convert more types,
eventually recursively attempting to layout 'C' again, at which point we
would say that layout was complete, even though we were still in the
middle of it.

By not setting the body, we correctly signal that layout is not
complete, and things work as expected.

At some point, it might be worth refactoring this to avoid looking at
the LLVM IR types under construction.

llvm-svn: 202320
2014-02-27 00:03:39 +00:00
David Majnemer e385d89ce6 IRGen: Simplify alignment calculation in setBitFieldInfo
Take advantage of CharUnits::alignmentAtOffset instead of calculating it
by hand.

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

llvm-svn: 202098
2014-02-25 01:20:15 +00:00
David Majnemer 7a72601099 IRGen: Fix build breakage
MSVC allows extra-qualification on member functions, it lets you repeat
the class name on the method.

llvm-svn: 201918
2014-02-22 00:41:07 +00:00
Warren Hunt 0afa2d2f2b Fix two warnings introduced r201907
Unused variable is removed.  Construction order is changed to match 
declaration order.

llvm-svn: 201914
2014-02-22 00:22:15 +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
Yunzhong Gao eeeb8dafed Fixing PR18430 by checking that the size of bitfields plus padding does not
grow into the following virtual base.

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

llvm-svn: 200359
2014-01-29 00:09:16 +00:00
Yunzhong Gao 063763ea42 Fixing PR18510 by checking whether the non-virtual base of the derived class
might have a smaller size as compared to the stand-alone type of the base class.
This is possible when the derived class is packed and hence might have smaller
alignment requirement than the base class.

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

llvm-svn: 200031
2014-01-24 19:28:24 +00:00
NAKAMURA Takumi ae6f9d4460 CGRecordLayoutBuilder.cpp: Clarify if-else. [-Wdangling-else]
llvm-svn: 198906
2014-01-10 00:54:50 +00:00
Warren Hunt 640015cbc3 [ms-abi] Fixing CGRecordLayoutBuilder w.r.t. MS NonVirutalBase Layout
The MS abi lays out *all* non-virtual bases with leading vfptrs before 
laying out non-virutal bases without vfptrs.  This guarantees that the 
primary base is laid out first.  r198818 fixed RecordLayoutBuilder to 
produce compatiable layouts.  This patch fixes CGRecordLayoutBuilder to 
be able to consume those layouts and produce meaningful output without 
tripping any asserts about assumed incoming layout.

A test case is included that shows CGRecordLayoutBuilder in fact 
produces output in the compatiable order.

llvm-svn: 198900
2014-01-09 23:51:31 +00:00
Warren Hunt d640d7d96e [ms-abi] Refactor Microsoft Record Layout
This patch refactors microsoft record layout to be more "natural".  The 
most dominant change is that vbptrs and vfptrs are injected after the 
fact.  This simplifies the implementation and the math for the offest 
for the first base/field after the vbptr.

llvm-svn: 198818
2014-01-09 00:30:56 +00:00
Alp Toker f6a24ce40f Fix a tranche of comment, test and doc typos
llvm-svn: 196510
2013-12-05 16:25:25 +00:00
Hans Wennborg 96655c0ee4 Fix typo in CGRecordLayoutBuilder.cpp: s/Field/Fields/ in comment
llvm-svn: 194863
2013-11-15 22:31:11 +00:00
Warren Hunt 7c55e7ef0e Minor efficiency refactor related to 193661. No functional change.
llvm-svn: 193665
2013-10-30 00:14:55 +00:00
Warren Hunt dbbc5dfd12 Fixing code gen to handle microsoft layouts for which size % alignment
!= 0

llvm-svn: 193661
2013-10-29 23:49:26 +00:00
Warren Hunt 8f8bad723d Adds Microsoft compatiable C++ record layout code to clang.
llvm-svn: 192494
2013-10-11 20:19:00 +00:00
Argyrios Kyrtzidis 8ade08edba Changes so that a few tests do not fail when running under guarded malloc.
Guarded malloc emits some messages at the beginning in stderr when enabled.
These messages caused a few tests to fail.

llvm-svn: 186219
2013-07-12 22:30:03 +00:00
Eli Friedman 2782dacfbc Rewrite record layout for ms_struct structs.
The old implementation of ms_struct in RecordLayoutBuilder was a
complete mess: it depended on complicated conditionals which didn't
really reflect the underlying logic, and placed a burden on users of
the resulting RecordLayout. This commit rips out almost all of the
old code, and replaces it with simple checks in
RecordLayoutBuilder::LayoutBitField.

This commit also fixes <rdar://problem/14252115>, a bug where class
inheritance would cause us to lay out bitfields incorrectly.

llvm-svn: 185018
2013-06-26 20:50:34 +00:00
John McCall c8e0170578 Standardize accesses to the TargetInfo in IR-gen.
Patch by Stephen Lin!

llvm-svn: 179638
2013-04-16 22:48:15 +00:00
John McCall 359b885e12 First pass at abstracting out a class for the target C++ ABI.
llvm-svn: 173514
2013-01-25 22:30:49 +00:00
David Greene 464d219576 Fix signed/unsigned Compare
Do some casting to avoid a signed/unsigned compare.

llvm-svn: 172571
2013-01-15 23:13:49 +00:00
Chandler Carruth ffd5551bc7 Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to
reflect the migration in r171366.

Re-sort the #include lines to reflect the new paths.

llvm-svn: 171369
2013-01-02 11:45:17 +00:00
Eli Bendersky 76bd3d8599 Fix a compilation warning with gcc 4.6
llvm-svn: 170440
2012-12-18 18:53:14 +00:00
Chandler Carruth ed72cdc010 Cleanup and fix an assert that was mis-firing.
Note that there is no test suite update. This was found by a couple of
tests failing when the test suite was run on a powerpc64 host (thanks
Roman!). The tests don't specify a triple, which might seem surprising
for a codegen test. But in fact, these tests don't even inspect their
output. Not at all. I could add a bunch of triples to these tests so
that we'd get the test coverage for normal builds, but really someone
needs to go through and add actual *tests* to these tests. =[ The ones
in question are:

  test/CodeGen/bitfield-init.c
  test/CodeGen/union.c

llvm-svn: 169694
2012-12-09 10:33:27 +00:00
Chandler Carruth fd8eca202f Fix the bitfield record layout in codegen for big endian targets.
This was an egregious bug due to the several iterations of refactorings
that took place. Size no longer meant what it original did by the time
I finished, but this line of code never got updated. Unfortunately we
had essentially zero tests for this in the regression test suite. =[

I've added a PPC64 run over the bitfield test case I've been primarily
using. I'm still looking at adding more tests and making sure this is
the *correct* bitfield access code on PPC64 linux, but it looks pretty
close to me, and it is *worlds* better than before this patch as it no
longer asserts! =] More commits to follow with at least additional tests
and maybe more fixes.

Sorry for the long breakage due to this....

llvm-svn: 169691
2012-12-09 07:26:04 +00:00
Chandler Carruth ff0e3a1e1c Rework the bitfield access IR generation to address PR13619 and
generally support the C++11 memory model requirements for bitfield
accesses by relying more heavily on LLVM's memory model.

The primary change this introduces is to move from a manually aligned
and strided access pattern across the bits of the bitfield to a much
simpler lump access of all bits in the bitfield followed by math to
extract the bits relevant for the particular field.

This simplifies the code significantly, but relies on LLVM to
intelligently lowering these integers.

I have tested LLVM's lowering both synthetically and in benchmarks. The
lowering appears to be functional, and there are no really significant
performance regressions. Different code patterns accessing bitfields
will vary in how this impacts them. The only real regressions I'm seeing
are a few patterns where the LLVM code generation for loads that feed
directly into a mask operation don't take advantage of the x86 ability
to do a smaller load and a cheap zero-extension. This doesn't regress
any benchmark in the nightly test suite on my box past the noise
threshold, but my box is quite noisy. I'll be watching the LNT numbers,
and will look into further improvements to the LLVM lowering as needed.

llvm-svn: 169489
2012-12-06 11:14:44 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
Eli Friedman 9ee2d04753 Make -mms-bitfields behave consistently.
Patch by Jeremiah Zanin.

llvm-svn: 165849
2012-10-12 23:29:20 +00:00
Micah Villmow dd31ca10ef Move TargetData to DataLayout.
llvm-svn: 165395
2012-10-08 16:25:52 +00:00
Eli Friedman c24e2fb1fb Propagate lvalue alignment into bitfields. Per report on cfe-dev.
llvm-svn: 159295
2012-06-27 21:19:48 +00:00
David Blaikie 40ed29730b Revert Decl's iterators back to pointer value_type rather than reference value_type
In addition, I've made the pointer and reference typedef 'void' rather than T*
just so they can't get misused. I would've omitted them entirely but
std::distance likes them to be there even if it doesn't use them.

This rolls back r155808 and r155869.

Review by Doug Gregor incorporating feedback from Chandler Carruth.

llvm-svn: 158104
2012-06-06 20:45:41 +00:00
John McCall e42a336604 Add support for laying out vtordisps according to our current
working knowledge of the Microsoft ABI.  Based on a patch by
Dmitry Sokolov.

llvm-svn: 155905
2012-05-01 08:55:32 +00:00
David Blaikie 2d7c57ec1d Remove the ref/value inconsistency in filter_decl_iterator.
filter_decl_iterator had a weird mismatch where both op* and op-> returned T*
making it difficult to generalize this filtering behavior into a reusable
library of any kind.

This change errs on the side of value, making op-> return T* and op* return
T&.

(reviewed by Richard Smith)

llvm-svn: 155808
2012-04-30 02:36:29 +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
David Blaikie bbafb8a745 Unify naming of LangOptions variable/get function across the Clang stack (Lex to AST).
The member variable is always "LangOpts" and the member function is always "getLangOpts".

Reviewed by Chris Lattner

llvm-svn: 152536
2012-03-11 07:00:24 +00:00
Chandler Carruth 52b6ac2a78 Silence a GCC warning about a set-but-not-used variable in release builds.
llvm-svn: 152005
2012-03-04 12:16:40 +00:00
Eli Friedman 09d272d025 A base subobject type doesn't make sense for unions; don't try to compute it. Based on patch by Yin Ma. Fixes PR11751.
llvm-svn: 148093
2012-01-13 03:58:31 +00:00
Eli Friedman 3c840aad54 Make CGRecordLayoutBuilder correctly switch over to a packed class when a class has a base whose alignment will break the class layout. <rdar://problem/10551376>.
llvm-svn: 146443
2011-12-12 23:13:20 +00:00
Eli Friedman dae858aca3 Make sure we correctly zero-initialize unions containing a pointer to data member as the first field. PR11487.
llvm-svn: 146009
2011-12-07 01:30:11 +00:00
John McCall 0153cd3027 Fix the layout of vb-tables and vf-tables in the MS C++ ABI.
Based on work by Dmitry Sokolov!

llvm-svn: 144072
2011-11-08 04:01:03 +00:00
Eli Friedman 5e9534b0ae Rewrite parts of MS ABI C++ layout. Based on work by r4start; I ended up doing this while I was trying to review his patch.
llvm-svn: 142325
2011-10-18 00:55:28 +00:00
Richard Smith caf3390d44 Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions,
   and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert
   behaviour.
 - Factor out evaluation of bitfield bit widths.
 - Fix a few places which would evaluate an expression twice: once to determine
   whether it is a constant expression, then again to get the value.

llvm-svn: 141561
2011-10-10 18:28:20 +00:00
Douglas Gregor e8bbc12152 Extend the ASTContext constructor to delay the initialization of
builtin types (When requested). This is another step toward making
ASTUnit build the ASTContext as needed when loading an AST file,
rather than doing so after the fact. No actual functionality change (yet).

llvm-svn: 138985
2011-09-02 00:18:52 +00:00
Chris Lattner 5ec04a51fa switch clang to use the new-new way of creating llvm::StructType's.
llvm-svn: 137472
2011-08-12 17:43:31 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Chris Lattner 2192fe50da de-constify llvm::Type, patch by David Blaikie!
llvm-svn: 135370
2011-07-18 04:24:23 +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