aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGClass.cpp
AgeCommit message (Collapse)AuthorFilesLines
2013-06-19[ms-cxxabi] Emit and install appropriately mangled vbtablesReid Kleckner1-1/+2
In Itanium, dynamic classes have one vtable with several different address points for dynamic base classes that can't share vtables. In the MS C++ ABI, each vbtable that can't be shared gets its own symbol, similar to how ctor vtables work in Itanium. However, instead of mangling the subobject offset into the symbol, the unique portions of the inheritance path are mangled into the symbol to make it unique. This patch implements the MSVC 2012 scheme for forming unique vbtable symbol names. MSVC 2010 use the same mangling with a different subset of the path. Implementing that mangling and possibly others is TODO. Each vbtable is an array of i32 offsets from the vbptr that points to it to another virtual base subobject. The first entry of a vbtable always points to the base of the current subobject, implying that it is the same no matter which parent class contains it. Reviewers: rjmccall Differential Revision: http://llvm-reviews.chandlerc.com/D636 llvm-svn: 184309
2013-06-18CodeGen: Have 'this'-returning constructors and destructors to take ↵Stephen Lin1-11/+3
advantage of the new backend 'returned' attribute. The backend will now use the generic 'returned' attribute to form tail calls where possible, as well as avoid save-restores of 'this' in some cases (specifically the cases that matter for the ARM C++ ABI). This patch also reverts a prior front-end only partial implementation of these optimizations, since it's no longer required. llvm-svn: 184205
2013-06-12PR12086, PR15117Richard Smith1-52/+41
Introduce CXXStdInitializerListExpr node, representing the implicit construction of a std::initializer_list<T> object from its underlying array. The AST representation of such an expression goes from an InitListExpr with a flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr). This more detailed representation has several advantages, the most important of which is that the new MaterializeTemporaryExpr allows us to directly model lifetime extension of the underlying temporary array. Using that, this patch *drastically* simplifies the IR generation of this construct, provides IR generation support for nested global initializer_list objects, fixes several bugs where the destructors for the underlying array would accidentally not get invoked, and provides constant expression evaluation support for std::initializer_list objects. llvm-svn: 183872
2013-05-29[ms-cxxabi] Implement MSVC virtual base adjustmentReid Kleckner1-25/+6
While we can't yet emit vbtables, this allows us to find virtual bases of objects constructed in other TUs. This make iostream hello world work, since basic_ostream virtually inherits from basic_ios. Differential Revision: http://llvm-reviews.chandlerc.com/D795 llvm-svn: 182870
2013-05-07Weaken an assertion in memcpyization to account forJohn McCall1-2/+6
unnamed bitfields. Unnamed bitfields won't have an explicit copy operation in the AST, which breaks the strong form of the invariant. rdar://13816940 llvm-svn: 181289
2013-05-03Correctly emit certain implicit references to 'self' even withinJohn McCall1-3/+3
a lambda. Bug #1 is that CGF's CurFuncDecl was "stuck" at lambda invocation functions. Fix that by generally improving getNonClosureContext to look through lambdas and captured statements but only report code contexts, which is generally what's wanted. Audit uses of CurFuncDecl and getNonClosureAncestor for correctness. Bug #2 is that lambdas weren't specially mapping 'self' when inside an ObjC method. Fix that by removing the requirement for that and using the normal EmitDeclRefLValue path in LoadObjCSelf. rdar://13800041 llvm-svn: 181000
2013-04-20C++1y: Allow aggregates to have default initializers.Richard Smith1-0/+1
Add a CXXDefaultInitExpr, analogous to CXXDefaultArgExpr, and use it both in CXXCtorInitializers and in InitListExprs to represent a default initializer. There's an additional complication here: because the default initializer can refer to the initialized object via its 'this' pointer, we need to make sure that 'this' points to the right thing within the evaluation. llvm-svn: 179958
2013-04-16Standardize accesses to the TargetInfo in IR-gen.John McCall1-2/+2
Patch by Stephen Lin! llvm-svn: 179638
2013-03-20Exploit this-return of a callsite in a this-return function.Manman Ren1-4/+13
For constructors/desctructors that return 'this', if there exists a callsite that returns 'this' and is immediately before the return instruction, make sure we are using the return value from the callsite. We don't need to keep 'this' alive through the callsite. It also enables optimizations in the backend, such as tail call optimization. Updated from r177211. rdar://12818789 llvm-svn: 177541
2013-03-16revert r177211 due to its potential issuesManman Ren1-13/+4
llvm-svn: 177222
2013-03-16Exploit this-return of a callsite in a this-return function.Manman Ren1-4/+13
For constructors/desctructors that return 'this', if there exists a callsite that returns 'this' and is immediately before the return instruction, make sure we are using the return value from the callsite. We don't need to keep 'this' alive through the callsite. It also enables optimizations in the backend, such as tail call optimization. rdar://12818789 llvm-svn: 177211
2013-03-07Change hasAggregateLLVMType, which conflates complex andJohn McCall1-10/+18
aggregate types in a profoundly wrong way that has to be worked around in every call site, to getEvaluationKind, which classifies and distinguishes between all of these cases. Also, normalize the API for loading and storing complexes. I'm working on a larger patch and wanted to pull these changes out, but it would have be annoying to detangle them from each other. llvm-svn: 176656
2013-03-05Use ASTContext::getDeclAlign(<Field Decl>) to get the alignment of the firstLang Hames1-3/+1
field to be memcpy'd, rather instead of ASTContext::getTypeAlign(<Field Type>). For packed structs the alignment of a field may be less than the alignment of the field's type. <rdar://problem/13338585> llvm-svn: 176512
2013-02-27Better support for constructors with -cxx-abi microsoft, partly fixes PR12784Timur Iskhodzhanov1-43/+56
llvm-svn: 176186
2013-02-27Use the correct alignment for POD-member memcpys where the first field is aLang Hames1-7/+10
bitfield. CGBitField::StorageAlignment holds the alignment in chars, but emitMemcpy had been treating it as if it were held in bits, leading to underaligned memcpys. Related to PR15348. Thanks very much to Chandler for the diagnosis. llvm-svn: 176163
2013-02-17Re-apply r174919 - smarter copy/move assignment/construction, with fixes forLang Hames1-1/+369
bitfield related issues. The original commit broke Takumi's builder. The bug was caused by bitfield sizes being determined by their underlying type, rather than the field info. A similar issue with bitfield alignments showed up on closer testing. Both have been fixed in this patch. llvm-svn: 175389
2013-02-13ubsan: Add checking for invalid downcasts. Per [expr.static.cast]p2 and p11,Richard Smith1-1/+1
base-to-derived casts have undefined behavior if the object is not actually an instance of the derived type. llvm-svn: 175078
2013-02-13Emit virtual/deleting destructors properly with -cxx-abi microsoft, PR15058Timur Iskhodzhanov1-3/+38
llvm-svn: 175045
2013-02-12Backing out r174919 while I investigate a self-host bug on Takumi's builder.Lang Hames1-358/+1
llvm-svn: 174925
2013-02-11When generating IR for default copy-constructors, copy-assignment operators,Lang Hames1-1/+358
move-constructors and move-assignment operators, use memcpy to copy adjacent POD members. Previously, classes with one or more Non-POD members would fall back on element-wise copies for all members, including POD members. This often generated a lot of IR. Without padding metadata, it wasn't often possible for the LLVM optimizers to turn the element-wise copies into a memcpy. This code hasn't yet received any serious tuning. I didn't see any serious regressions on a self-hosted clang build, or any of the nightly tests, but I think it's important to get this out in the wild to get more testing. Insights, feedback and comments welcome. Many thanks to David Blaikie, Richard Smith, and especially John McCall for their help and feedback on this work. llvm-svn: 174919
2013-02-01Destroy arrays and ARC fields when throwing out of ctors.John McCall1-30/+6
Previously we were only handling non-array fields of class type. Testcases derived from a patch by WenHan Gu. llvm-svn: 174146
2013-01-31When we're emitting a constructor or destructor call from a delegatingDouglas Gregor1-15/+25
constructor, retrieve our VTT parameter directly. Fixes PR14588 / <rdar://problem/12867962>. llvm-svn: 174042
2013-01-25First pass at abstracting out a class for the target C++ ABI.John McCall1-2/+3
llvm-svn: 173514
2012-12-24CGClass.cpp: [PR14335] Remove comma-separated \param, for now. [-Wdocumentation]NAKAMURA Takumi1-4/+0
/// \param argBegin,argEnd the arguments to evaluate and pass to the constructor llvm-svn: 171015
2012-12-20Rename llvm::Attributes to llvm::Attribute.Bill Wendling1-1/+1
llvm-svn: 170722
2012-12-20Revert r170500. It over-zealously converted *ALL* things named Attributes, ↵Bill Wendling1-1/+1
which is wrong here. llvm-svn: 170721
2012-12-19Rename the 'Attributes' class to 'Attribute'. It's going to represent a ↵Bill Wendling1-1/+1
single attribute in the future. llvm-svn: 170500
2012-12-19Change DeclContextLookup(Const)Result to (Mutable)ArrayRef<NamedDecl*>, as ↵David Blaikie1-1/+1
per review discussion in r170365 This does limit these typedefs to being sequences, but no current usage requires them to be contiguous (we could expand this to a more general iterator pair range concept at some point). Also, it'd be nice if SmallVector were constructible directly from an ArrayRef but this is a bit tricky since ArrayRef depends on SmallVectorBaseImpl for the inverse conversion. (& generalizing over all range-like things, while nice, would require some nontrivial SFINAE I haven't thought about yet) llvm-svn: 170482
2012-12-13Make sure the __invoke function for lambdas returns properly. Per bug ↵Eli Friedman1-0/+2
report on IRC> llvm-svn: 170160
2012-11-07When deciding whether to convert an array construction loop into a memcpy, lookRichard Smith1-11/+4
at whether the *selected* constructor would be trivial rather than considering whether the array's element type has *any* non-trivial constructors of the relevant kind. llvm-svn: 167562
2012-11-01Simplify: replace getContext().getLangOpts() with just getLangOpts().Richard Smith1-2/+2
llvm-svn: 167261
2012-10-23Switch CodeGenOptions over to a .def file, like we do with LangOptions.Douglas Gregor1-1/+1
llvm-svn: 166497
2012-10-10Have 'addFnAttr' take the attribute enum value. Then have it build the ↵Bill Wendling1-1/+1
attribute object and add it appropriately. No functionality change. llvm-svn: 165596
2012-10-09-fcatch-undefined-behavior: emit calls to the runtime library whenever one ↵Richard Smith1-2/+6
of the checks fails. llvm-svn: 165536
2012-08-08Fix an assertion failure with a C++ constructor initializing aEli Friedman1-6/+9
member of reference type in an anonymous struct. PR13154. llvm-svn: 161473
2012-08-01When devirtualizing the conversion to a virtual base subobject,John McCall1-57/+64
don't explode if the offset we get is zero. This can happen if you have an empty virtual base class. While I'm at it, remove an unnecessary block from the IR-generation of the null-check, mark the eventual GEP as inbounds, and generally prettify. llvm-svn: 161100
2012-07-07Distinguish more carefully between free functions and C++ instance methodsJohn McCall1-27/+31
in the ABI arrangement, and leave a hook behind so that we can easily tweak CCs on platforms that use different CCs by default for C++ instance methods. llvm-svn: 159894
2012-06-06Revert Decl's iterators back to pointer value_type rather than reference ↵David Blaikie1-3/+3
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-04-30Remove the ref/value inconsistency in filter_decl_iterator.David Blaikie1-3/+3
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-27Use enum to set debug info size generated by ClangAlexey Samsonov1-1/+2
llvm-svn: 155697
2012-04-20Fix bug 12574 - Avoid infinite recursion in constructors and destructors ↵Timur Iskhodzhanov1-2/+3
when using Microsoft C++ ABI llvm-svn: 155189
2012-04-16Propagate alignment on lvalues through EmitLValueForField. PR12395.Eli Friedman1-4/+9
llvm-svn: 154789
2012-03-30Add a note about a missing optimization in the case of virtualJohn McCall1-0/+3
inheritance. llvm-svn: 153722
2012-03-29Revert r153613 as it's causing large compile-time regressions on the nightly ↵Chad Rosier1-10/+4
testers. llvm-svn: 153660
2012-03-28When we can't prove that the target of an aggregate copy isJohn McCall1-4/+10
a complete object, the memcpy needs to use the data size of the structure instead of its sizeof() value. Fixes PR12204. llvm-svn: 153613
2012-03-26add tbaa metadata to vtable pointer loads/storesKostya Serebryany1-2/+5
llvm-svn: 153447
2012-03-11Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie1-7/+7
(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-01Implement "optimization" for lambda-to-block conversion which inlines the ↵Eli Friedman1-2/+0
generated block literal for lambdas which are immediately converted to block pointer type. This simplifies the AST, avoids an unnecessary copy of the lambda and makes it much easier to avoid copying the result onto the heap. Note that this transformation has a substantial semantic effect outside of ARC: it gives the converted lambda lifetime semantics similar to a block literal. With ARC, the effect is much less obvious because the lifetime of blocks is already managed. llvm-svn: 151797
2012-02-28Prefer bitcast+GEP over ptrtoint+sub+inttoptr: it's semantically equivalent ↵Eli Friedman1-3/+3
here, and generally nicer to the optimizer. llvm-svn: 151659
2012-02-26Ensure that we delete destructors in the right cases. Specifically:Richard Smith1-0/+4
- variant members with nontrivial destructors make the containing class's destructor deleted - check for a virtual destructor after checking for overridden methods in the base class(es) - check for an inaccessible operator delete for a class with a virtual destructor. Do not try to call an anonymous union field's destructor from the destructor of the containing class. llvm-svn: 151483