summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGVTables.cpp
Commit message (Collapse)AuthorAgeFilesLines
* PR22051: Missing debug location on calls in dtor thunks in Windows.David Blaikie2014-12-291-1/+1
| | | | llvm-svn: 224963
* Use std::find_if instead of manual loop.David Blaikie2014-12-291-8/+4
| | | | llvm-svn: 224960
* CodeGen: Virtual dtor thunks shouldn't have this marked as 'returned'David Majnemer2014-11-011-1/+1
| | | | | | | The ARM ABI virtual destructor thunks cannot be marked as 'returned' because they return undef. llvm-svn: 221042
* MS ABI: Properly call global delete when invoking virtual destructorsDavid Majnemer2014-10-311-4/+10
| | | | | | | | | | | | | | | | | | | | Summary: The Itanium ABI approach of using offset-to-top isn't possible with the MS ABI, it doesn't have that kind of information lying around. Instead, we do the following: - Call the virtual deleting destructor with the "don't delete the object flag" set. The virtual deleting destructor will return a pointer to 'this' adjusted to the most derived class. - Call the global delete using the adjusted 'this' pointer. Reviewers: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5996 llvm-svn: 220993
* Don't emit strong vtable definitions for imported classes with key functions ↵Hans Wennborg2014-10-231-1/+2
| | | | | | | | | | | | | | | | | | | (PR21355) Clang would previously assert on the following code when targeting MinGW: struct __declspec(dllimport) S { virtual ~S(); }; S::~S() {} Because ~S is a key function and the class is dllimport, we would try to emit a strong definition of the vtable, with dllimport - which is a conflict. We should not emit strong vtable definitions for imported classes. Differential Revision: http://reviews.llvm.org/D5944 llvm-svn: 220532
* Simplify a few loops over CallArgList/FunctionArgList. NFCAlexey Samsonov2014-08-131-4/+1
| | | | llvm-svn: 215571
* MS ABI: Use musttail for vtable thunks that pass arguments by valueReid Kleckner2014-07-261-2/+71
| | | | | | | | | | | | | This moves some memptr specific code into the generic thunk emission codepath. Fixes PR20053. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D4613 llvm-svn: 214004
* Remove an extra parameter and C++11 for loop-ify this codeReid Kleckner2014-07-261-9/+7
| | | | llvm-svn: 214003
* MS ABI: Don't push destructor cleanups for aggregate parameters in thunksReid Kleckner2014-07-251-0/+1
| | | | | | | | The target method of the thunk will perform the cleanup. This can't be tested in 32-bit x86 yet because passing something by value would create an inalloca, and we refuse to generate broken code for that. llvm-svn: 213976
* MS ABI: Reference MSVC RTTI from the VFTableDavid Majnemer2014-07-011-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pointer for a class's RTTI data comes right before the VFTable but has no name. To be properly compatible with this, we do the following: * Create a single GlobalVariable which holds the contents of the VFTable _and_ the pointer to the RTTI data. * Create a GlobalAlias, with appropriate linkage/visibility, that points just after the RTTI data pointer. This ensures that the VFTable symbol will always refer to VFTable data. * Create a Comdat with a "Largest" SelectionKind and stick the private GlobalVariable in it. By transitivity, the GlobalAlias will be a member of the Comdat group. Using "Largest" ensures that foreign definitions without an RTTI data pointer will _not_ be chosen in the final linked image. Whether or not we emit RTTI data depends on several things: * The -fno-rtti flag implies that we should never not emit a pointer to RTTI data before the VFTable. * __declspec(dllimport) brings in the VFTable from a remote DLL. Use an available_externally GlobalVariable to provide a local definition of the VFTable. This means that we won't have any available_externally definitions of things like complete object locators. This is acceptable because they are never directly referenced. To my knowledge, this completes the implementation of MSVC RTTI code generation. Further semantic work should be done to properly support /GR-. llvm-svn: 212125
* MS ABI: Update the thunk linkage computationHans Wennborg2014-06-061-2/+4
| | | | | | | | | | | | | | | | | | | | | | | As suggested by Reid: - class has GVA_Internal linkage -> internal - thunk has return adjustment -> weak_odr, to handle evil corner case [1] - all other normal methods -> linkonce_odr 1. Evil corner case: struct Incomplete; struct A { int a; virtual A *bar(); }; struct B { int b; virtual B *foo(Incomplete); }; struct C : A, B { int c; virtual C *foo(Incomplete); }; C c; Here, the thunk for C::foo() will be emitted when C::foo() is defined, which might be in a different translation unit, so it needs to be weak_odr. Differential Revision: http://reviews.llvm.org/D3992 llvm-svn: 210368
* Start adding support for dllimport/dllexport on classes (PR11170)Hans Wennborg2014-05-301-3/+16
| | | | | | | | | | | | | | | | This implements the central part of support for dllimport/dllexport on classes: allowing the attribute on class declarations, inheriting it to class members, and forcing emission of exported members. It's based on Nico Rieck's patch from http://reviews.llvm.org/D1099. This patch doesn't propagate dllexport to bases that are template specializations, which is an interesting problem. It also doesn't look at the rules when redeclaring classes with different attributes, I'd like to do that separately. Differential Revision: http://reviews.llvm.org/D3877 llvm-svn: 209908
* [C++11] Use 'nullptr'. CodeGen edition.Craig Topper2014-05-211-10/+10
| | | | llvm-svn: 209272
* Simplify a few cast<>s.Rafael Espindola2014-05-081-9/+12
| | | | llvm-svn: 208331
* Debug info: (Bugfix) Make sure artificial functions like _GLOBAL__I_aAdrian Prantl2014-04-101-1/+1
| | | | | | | | | | | | | | | | are not associated with any source lines. Previously, if the Location of a Decl was empty, EmitFunctionStart would just keep using CurLoc, which would sometimes be correct (e.g., thunks) but in other cases would just point to a hilariously random location. This patch fixes this by completely eliminating all uses of CurLoc from EmitFunctionStart and rather have clients explicitly pass in a SourceLocation for the function header and the function body. rdar://problem/14985269 llvm-svn: 205999
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-071-1/+1
| | | | | | This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
* Remove the -fhidden-weak-vtables -cc1 option. It was dead,John McCall2014-02-081-43/+1
| | | | | | gross, and increasingly replaced through other mechanisms. llvm-svn: 201011
* MS ABI: Mangle member pointer template argumentsReid Kleckner2014-02-051-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Member pointers are mangled as they would be represented at runtime. They can be a single integer literal, single decl, or a tuple with some more numbers tossed in. With Clang today, most of those numbers will be zero because we reject pointers to members of virtual bases. This change required moving VTableContextBase ownership from CodeGenVTables to ASTContext, because mangling now depends on vtable layout. I also hoisted the inheritance model helpers up to be inline static methods of MSInheritanceAttr. This makes the AST code that deals with member pointers much more readable. MSVC doesn't appear to have stable manglings of null member pointers: - Null data memptrs in function templates have a mangling collision with the first field of a non-polymorphic single inheritance class. - The mangling of null data memptrs changes if you add casts. - Large null function memptrs in class templates crash MSVC. Clang uses the class template mangling for null data memptrs and the function template mangling for null function memptrs to deal with this. Reviewers: majnemer Differential Revision: http://llvm-reviews.chandlerc.com/D2695 llvm-svn: 200857
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-3/+3
| | | | | | | | | | | | | | | A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. llvm-svn: 200082
* Eliminate the ItaniumVTableContext object from CodeGenVTablesReid Kleckner2013-12-201-15/+8
| | | | | | | | | | | | | Now CodeGenVTables has only one VTableContext object, which is either Itanium or Microsoft. Fixes a FIXME with no functionality change intended. Ideally we could avoid the downcasts by pushing the things that reference the Itanium vtable context into ItaniumCXXABI.cpp, but we're not there yet. llvm-svn: 197845
* [ms-cxxabi] The 'most derived' ctor parameter usually comes lastReid Kleckner2013-12-171-1/+4
| | | | | | | | | | | | | | Unlike Itanium's VTTs, the 'most derived' boolean or bitfield is the last parameter for non-variadic constructors, rather than the second. For variadic constructors, the 'most derived' parameter comes after the 'this' parameter. This affects constructor calls and constructor decls in a variety of places. Reviewers: timurrrr Differential Revision: http://llvm-reviews.chandlerc.com/D2405 llvm-svn: 197518
* Avoid adding some decls to DeferredDeclsToEmit.Rafael Espindola2013-12-091-1/+2
| | | | | | | | Before this patch GetOrCreateLLVMFunction would add a decl to DeferredDeclsToEmit even when it was being called by the function trying to emit that decl. llvm-svn: 196753
* CodeGen: Don't emit linkage on thunks that aren't emitted because they're ↵Benjamin Kramer2013-12-071-3/+4
| | | | | | | | | | | | vararg. This can happen when we're trying to emit a thunk with available_externally linkage with optimization enabled but bail because it doesn't make sense for vararg functions. PR18098. llvm-svn: 196658
* Correct hyphenations in comments and assert messagesAlp Toker2013-12-051-1/+1
| | | | | | | This patch tries to avoid unrelated changes other than fixing a few hyphen-related ambiguities in nearby lines. llvm-svn: 196466
* [-cxx-abi microsoft] Emit thunks for pointers to virtual member functionsHans Wennborg2013-11-151-40/+62
| | | | | | | | | | | | | | | | Instead of storing the vtable offset directly in the function pointer and doing a branch to check for virtualness at each call site, the MS ABI generates a thunk for calling the function at a specific vtable offset, and puts that in the function pointer. This patch adds support for emitting such thunks. However, it doesn't support pointers to virtual member functions that are variadic, have an incomplete aggregate return type or parameter, or are overriding a function in a virtual base class. Differential Revision: http://llvm-reviews.chandlerc.com/D2104 llvm-svn: 194827
* Fix vbtable indices when a class shares the vbptr with a non-virtual baseTimur Iskhodzhanov2013-11-051-8/+7
| | | | llvm-svn: 194082
* Use aliases for more constructors and destructors.Rafael Espindola2013-11-041-4/+0
| | | | | | | | | | | | | | | | With this patch we produce alias for cases like template<typename T> struct foobar { foobar() { } }; template struct foobar<void>; We just have to be careful to produce the same aliases in every TU because of comdats. llvm-svn: 194000
* Add CodeGenABITypes.h for use in LLDB.Mark Lacey2013-10-301-0/+1
| | | | | | | | | | | | | | | | | | CodeGenABITypes is a wrapper built on top of CodeGenModule that exposes some of the functionality of CodeGenTypes (held by CodeGenModule), specifically methods that determine the LLVM types appropriate for function argument and return values. I addition to CodeGenABITypes.h, CGFunctionInfo.h is introduced, and the definitions of ABIArgInfo, RequiredArgs, and CGFunctionInfo are moved into this new header from the private headers ABIInfo.h and CGCall.h. Exposing this functionality is one part of making it possible for LLDB to determine the actual ABI locations of function arguments and return values, making it possible for it to determine this for any supported target without hard-coding ABI knowledge in the LLDB code. llvm-svn: 193717
* Make thunk this/return adjustment ABI-specific. Also, fix the return ↵Timur Iskhodzhanov2013-10-301-64/+9
| | | | | | | | adjustment when using -cxx-abi microsoft Reviewed at http://llvm-reviews.chandlerc.com/D2026 llvm-svn: 193679
* Use castAs instead of cast in thunk generationReid Kleckner2013-10-111-1/+1
| | | | | | | | Calling convention attributes can add sugar to methods that we have to look through. This fixes an assertion failure in the provided test case. llvm-svn: 192496
* Code cleanup: rename VTableContext to ItaniumVTableContext, VTableBuilder to ↵Timur Iskhodzhanov2013-10-091-1/+1
| | | | | | ItaniumVTableBuilder and clang-format code around llvm-svn: 192288
* Reland 192220 "Abstract out parts of thunk emission code, add support for ↵Timur Iskhodzhanov2013-10-091-25/+24
| | | | | | simple thunks when using -cxx-abi microsoft" with relaxed assertions llvm-svn: 192285
* Revert 192220 as it fails on an assertionTimur Iskhodzhanov2013-10-081-24/+25
| | | | llvm-svn: 192225
* Abstract out parts of thunk emission code, add support for simple thunks ↵Timur Iskhodzhanov2013-10-081-25/+24
| | | | | | | | when using -cxx-abi microsoft Reviewed at http://llvm-reviews.chandlerc.com/D1787 llvm-svn: 192220
* Extract ABI-specific parts of MangleContext into separate classesTimur Iskhodzhanov2013-10-031-3/+3
| | | | | | Reviewed at http://llvm-reviews.chandlerc.com/D1807 llvm-svn: 191878
* Thread a SourceLocation into the EmitCheck for "load_invalid_value". This occursNick Lewycky2013-10-021-1/+1
| | | | | | when scalars are loaded / undergo lvalue-to-rvalue conversion. llvm-svn: 191808
* Abstract out the emission of vtables, add basic support for vtable emission ↵Timur Iskhodzhanov2013-09-271-75/+4
| | | | | | | | when using -cxx-abi microsoft Reviewed at http://llvm-reviews.chandlerc.com/D1532 llvm-svn: 191523
* Don't emit an available_externally vtable pointing to linkonce_odr funcs.Rafael Espindola2013-09-031-20/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes pr13124. From the discussion at http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-June/022606.html we know that we cannot make funcions in a weak_odr vtable also weak_odr. They should remain linkonce_odr. The side effect is that we cannot emit a available_externally vtable unless we also emit a copy of the function. This also has an issue: If codegen is going to output a function, sema has to mark it used. Given llvm.org/pr9114, it looks like sema cannot be more aggressive at marking functions used because of vtables. This leaves us with a few unpleasant options: * Marking functions in vtables used if possible. This sounds a bit sloppy, so we should avoid it. * Producing available_externally vtables only when all the functions in it are already used or weak_odr. This would cover cases like -------------------- struct foo { virtual ~foo(); }; struct bar : public foo { virtual void zed(); }; void f() { foo *x(new bar); delete x; } void g(bar *x) { x->~bar(); // force the destructor to be used } -------------------------- and ---------------------------------- template<typename T> struct bar { virtual ~bar(); }; template<typename T> bar<T>::~bar() { } // make the destructor weak_odr instead of linkonce_odr extern template class bar<int>; void f() { bar<int> *x(new bar<int>); delete x; } ---------------------------- These look like corner cases, so it is unclear if it is worth it. * And finally: Just nuke this optimization. That is what this patch implements. llvm-svn: 189852
* Revert "PR14569: Omit debug info for thunks"David Blaikie2013-08-271-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | This reverts commit r189320. Alexey Samsonov and Dmitry Vyukov presented some arguments for keeping these around - though it still seems like those tasks could be solved by a tool just using the symbol table. In a very small number of cases, thunks may be inlined & debug info might be able to save profilers & similar tools from misclassifying those cases as part of the caller. The extra changes here plumb through the VarDecl for various cases to CodeGenFunction - this provides better fidelity through a few APIs but generally just causes the CGF::StartFunction to fallback to using the name of the IR function as the name in the debug info. The changes to debug-info-global-ctor-dtor.cpp seem like goodness. The two names that go missing (in favor of only emitting those names as linkage names) are names that can be demangled - emitting them only as the linkage name should encourage tools to do just that. Again, thanks to Dinesh Dwivedi for investigation/work on this issue. llvm-svn: 189421
* PR14569: Omit debug info for thunksDavid Blaikie2013-08-271-0/+1
| | | | | | | | | | | | | | | | | | This was added in r166676 based on PR13942 on the basis that tools may need debug information for any executable code/function for some fairly broad/non-specific purposes. It seems to me (as noted in PR14569) that the major/only purpose is in backtraces, which should generally not apply to thunks as they won't appear in the stack themselves. By removing them we fix PR14569 and reduce the size of Clang's debug info. Strangely enough this doesn't seem to have a substantial impact on Clang's self-hosted debug info (at least looking at DWO file size) size at all. Not sure if I failed to test this correctly but I only observed a 0.004% change in DWO file size over Clang+LLVM. With thanks to Dinesh Dwivedi for work on this PR. llvm-svn: 189320
* Simplify/clean up debug info suppression in CodeGenFunctionDavid Blaikie2013-08-261-3/+0
| | | | | | | | | | CodeGenFunction is run on only one function - a new object is made for each new function. I would add an assertion/flag to this effect, but there's an exception: ObjC properties involve emitting helper functions that are all emitted by the same CodeGenFunction object, so such a check is not possible/correct. llvm-svn: 189277
* DebugInfo: emit the definition of types when construction vtables are ↵David Blaikie2013-08-221-3/+6
| | | | | | | | | | required as these types may never end up emitting the full class data This might be able to be optimized further by only doing this in the absence of a key function, but it doesn't look like GCC is doing that so I'm not rushing to do it just yet. llvm-svn: 189022
* Revert "Revert "Revert "Revert "DebugInfo: Omit debug info for dynamic ↵David Blaikie2013-08-201-0/+3
| | | | | | | | | | | | | | classes in TUs that do not have the vtable for that class"""" This reverts commit r188687 (reverts r188642 (reverts 188600 (reverts 188576))). With added test coverage & fix for -gline-tables-only. Thanks Michael Gottesman for reverting this patch when it demonstrated problems & providing a reproduction/details to help me track this down. llvm-svn: 188739
* Revert "Revert "Revert "DebugInfo: Omit debug info for dynamic classes in ↵Michael Gottesman2013-08-191-3/+0
| | | | | | | | | | | | | TUs that do not have the vtable for that class""" This reverts commit r188642. This change is causing LTO builds to cause our 16 GB machines to swap and OOM all weekend. I am going to work with Dave Blaikie to resolve the issue. Sorry Dave =(. llvm-svn: 188687
* Revert "Revert "DebugInfo: Omit debug info for dynamic classes in TUs that ↵David Blaikie2013-08-181-0/+3
| | | | | | | | | | | | do not have the vtable for that class"" This reverts commit r188600. r188640/r188639 fixed the root cause of the crash-on-valid that r188600 originally introduced. This now appears to bootstrap debug clang successfully to the best of my testing. llvm-svn: 188642
* Revert "DebugInfo: Omit debug info for dynamic classes in TUs that do not ↵David Blaikie2013-08-171-3/+0
| | | | | | | | | | have the vtable for that class" This reverts commit r188576. Reverting while I investigate a selfhosting buildbot failure on Darwin. llvm-svn: 188600
* DebugInfo: Omit debug info for dynamic classes in TUs that do not have the ↵David Blaikie2013-08-161-0/+3
| | | | | | | | | vtable for that class This reduces Clang's .dwo (fission debug info) size by 23% over Clang+LLVM. llvm-svn: 188576
* Add MicrosoftVFTableContext to ASTTimur Iskhodzhanov2013-07-301-1/+25
| | | | llvm-svn: 187409
* Restore r184205 and associated commits (after commit of r185290)Stephen Lin2013-06-301-1/+2
| | | | | | This allows clang to use the backend parameter attribute 'returned' when generating 'this'-returning constructors and destructors in ARM and MSVC C++ ABIs. llvm-svn: 185291
* Revert r184205 and associated patches while investigating issue with broken ↵Stephen Lin2013-06-191-2/+1
| | | | | | | | buildbot (possible interaction with LTO) <rdar://problem/14209661> llvm-svn: 184384
OpenPOWER on IntegriCloud