aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGVTables.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-02-11Revert "Revert r260388 "[MS ABI] Never reference dllimport'd vtables""David Majnemer1-0/+5
This reverts commit r260449. We would supress our emission of vftable definitions if we thought another translation unit would provide the definition because we saw an explicit instantiation declaration. This is not the case with dllimport, we want to synthesize a definition of the vftable regardless. This fixes PR26569. llvm-svn: 260548
2016-01-29Use a consistent spelling for vtables.Eric Christopher1-12/+12
llvm-svn: 259137
2016-01-06[Driver] Add support for -fno-builtin-foo options.Chad Rosier1-2/+2
Addresses PR4941 and rdar://6756912. http://reviews.llvm.org/D15195 llvm-svn: 256937
2015-12-17[CUDA] Make vtable construction aware of host/device side of CUDA compilation.Artem Belevich1-0/+18
C++ emits vtables for classes that have key function present in the current TU. While we compile CUDA the fact that key function was found in this TU does not mean that we are going to generate code for it. E.g. vtable for a class with host-only methods should not (and can not) be generated on device side, because we'll never generate code for them during device-side compilation. This patch adds an extra CUDA-specific check during key method computation and filters out potential key methods that are not suitable for this side of CUDA compilation. When we codegen vtable, entries for unsuitable methods are set to null. Differential Revision: http://reviews.llvm.org/D15309 llvm-svn: 255911
2015-12-15Cross-DSO control flow integrity (Clang part).Evgeniy Stepanov1-2/+3
Clang-side cross-DSO CFI. * Adds a command line flag -f[no-]sanitize-cfi-cross-dso. * Links a runtime library when enabled. * Emits __cfi_slowpath calls is bitset test fails. * Emits extra hash-based bitsets for external CFI checks. * Sets a module flag to enable __cfi_check generation during LTO. This mode does not yet support diagnostics. llvm-svn: 255694
2015-11-06CodeGen: Remove implicit ilist iterator conversions, NFCDuncan P. N. Exon Smith1-6/+8
Make ilist iterator conversions explicit in clangCodeGen. Eventually I'll remove them everywhere. llvm-svn: 252358
2015-09-15Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski1-3/+3
Generating call assume(icmp %vtable, %global_vtable) after constructor call for devirtualization purposes. For more info go to: http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html Edit: Fixed version because of PR24479 and other bug caused in chrome. After this patch got reverted because of ScalarEvolution bug (D12719) Merged after John McCall big patch (Added Address). http://reviews.llvm.org/D11859 http://reviews.llvm.org/D12865 llvm-svn: 247646
2015-09-10Revert "Generating assumption loads of vptr after ctor call (fixed)"Piotr Padlewski1-3/+3
It seems that there is small bug, and we can't generate assume loads when some virtual functions have internal visibiliy This reverts commit 982bb7d966947812d216489b3c519c9825cacbf2. llvm-svn: 247332
2015-09-10CFI: Introduce -fsanitize=cfi-icall flag.Peter Collingbourne1-17/+21
This flag causes the compiler to emit bit set entries for functions as well as runtime bitset checks at indirect call sites. Depends on the new function bitset mechanism. Differential Revision: http://reviews.llvm.org/D11857 llvm-svn: 247238
2015-09-09Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski1-3/+3
Generating call assume(icmp %vtable, %global_vtable) after constructor call for devirtualization purposes. For more info go to: http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html Edit: Fixed version because of PR24479. After this patch got reverted because of ScalarEvolution bug (D12719) Merged after John McCall big patch (Added Address). http://reviews.llvm.org/D11859 llvm-svn: 247199
2015-09-08Compute and preserve alignment more faithfully in IR-generation.John McCall1-11/+25
Introduce an Address type to bundle a pointer value with an alignment. Introduce APIs on CGBuilderTy to work with Address values. Change core APIs on CGF/CGM to traffic in Address where appropriate. Require alignments to be non-zero. Update a ton of code to compute and propagate alignment information. As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment helper function to CGF and made use of it in a number of places in the expression emitter. The end result is that we should now be significantly more correct when performing operations on objects that are locally known to be under-aligned. Since alignment is not reliably tracked in the type system, there are inherent limits to this, but at least we are no longer confused by standard operations like derived-to-base conversions and array-to-pointer decay. I've also fixed a large number of bugs where we were applying the complete-object alignment to a pointer instead of the non-virtual alignment, although most of these were hidden by the very conservative approach we took with member alignment. Also, because IRGen now reliably asserts on zero alignments, we should no longer be subject to an absurd but frustrating recurring bug where an incomplete type would report a zero alignment and then we'd naively do a alignmentAtOffset on it and emit code using an alignment equal to the largest power-of-two factor of the offset. We should also now be emitting much more aggressive alignment attributes in the presence of over-alignment. In particular, field access now uses alignmentAtOffset instead of min. Several times in this patch, I had to change the existing code-generation pattern in order to more effectively use the Address APIs. For the most part, this seems to be a strict improvement, like doing pointer arithmetic with GEPs instead of ptrtoint. That said, I've tried very hard to not change semantics, but it is likely that I've failed in a few places, for which I apologize. ABIArgInfo now always carries the assumed alignment of indirect and indirect byval arguments. In order to cut down on what was already a dauntingly large patch, I changed the code to never set align attributes in the IR on non-byval indirect arguments. That is, we still generate code which assumes that indirect arguments have the given alignment, but we don't express this information to the backend except where it's semantically required (i.e. on byvals). This is likely a minor regression for those targets that did provide this information, but it'll be trivial to add it back in a later patch. I partially punted on applying this work to CGBuiltin. Please do not add more uses of the CreateDefaultAligned{Load,Store} APIs; they will be going away eventually. llvm-svn: 246985
2015-08-28Revert r246214 and r246213Steven Wu1-3/+3
These two commits causes llvm LTO bootstrap to hang in ScalarEvolution. llvm-svn: 246282
2015-08-27Assume loads fix #2Piotr Padlewski1-3/+3
There was linker problem, and it turns out that it is not always safe to refer to vtable. If the vtable is used, then we can refer to it without any problem, but because we don't know when it will be used or not, we can only check if vtable is external or it is safe to to emit it speculativly (when class it doesn't have any inline virtual functions). It should be fixed in the future. http://reviews.llvm.org/D12385 llvm-svn: 246214
2015-08-13Remove and forbid raw_svector_ostream::flush() calls.Yaron Keren1-2/+0
After r244870 flush() will only compare two null pointers and return, doing nothing but wasting run time. The call is not required any more as the stream and its SmallString are always in sync. Thanks to David Blaikie for reviewing. llvm-svn: 244928
2015-08-06Mark calls in thunk functions as tail-call optimization candidatesMichael Kuperstein1-0/+2
When a thunk is generated with a call to the original adjusted function, the thunk appears in the debugger call stack. We want the backend to perform tail-call optimization on the call, to make it invisible to the debugger. This fixes PR24235 Patch by: amjad.aboud@intel.com Differential Revision: http://reviews.llvm.org/D11476 llvm-svn: 244207
2015-08-01Rangify for loops, NFC.Yaron Keren1-2/+2
llvm-svn: 243841
2015-07-28Getting rid of old iterator loopsPiotr Padlewski1-8/+4
llvm-svn: 243431
2015-07-24Generating available_externally vtables for outline virtual functionsPiotr Padlewski1-12/+30
Generating available_externally vtables for optimizations purposes. Unfortunatelly ItaniumABI doesn't guarantee that we will be able to refer to virtual inline method by name. But when we don't have any inline virtual methods, and key function is not defined in this TU, we can generate that there will be vtable and mark it as available_externally. This is patch will help devirtualize better. Differential Revision: http://reviews.llvm.org/D11441 llvm-svn: 243090
2015-07-15Set comdat when an available_externally thunk is converted to linkonce_odr.Rafael Espindola1-12/+17
Fixes pr24130. llvm-svn: 242293
2015-07-15CodeGen: Improve CFI type blacklisting mechanism.Peter Collingbourne1-2/+6
We now use the sanitizer special case list to decide which types to blacklist. We also support a special blacklist entry for types with a uuid attribute, which are generally COM types whose virtual tables are defined externally. Differential Revision: http://reviews.llvm.org/D11096 llvm-svn: 242286
2015-07-13Set the linkage before setting the visibility.Rafael Espindola1-9/+8
Otherwise the visibility setting code would not know that a given function was available_externally. Fixes PR24097. llvm-svn: 242012
2015-07-09CFI: Emit correct bit set information if RTTI is disabled under MS ABI.Peter Collingbourne1-2/+6
We were previously creating bit set entries at virtual table offset sizeof(void*) unconditionally under the Microsoft C++ ABI. This is incorrect if RTTI data is disabled; in that case the "address point" is at offset 0. This change modifies bit set emission to take into account whether RTTI data is being emitted. Also make a start on a blacklisting scheme for records. Differential Revision: http://reviews.llvm.org/D11048 llvm-svn: 241845
2015-07-02Remove whitespace from start of line, NFC.Yaron Keren1-1/+1
llvm-svn: 241272
2015-06-30Fix use-after-free.Peter Collingbourne1-3/+6
llvm-svn: 241121
2015-06-30CodeGen: Assign an appropriate comdat to thunks.Peter Collingbourne1-10/+8
Previously we were not assigning a comdat to thunks in the Microsoft ABI, which would have required us to emit these functions outside of a comdat. (Due to an inconsistency in how we were emitting objects, we were getting this right most of the time, but only when compiling with function sections.) This code generator change causes us to create a comdat for each thunk. Differential Revision: http://reviews.llvm.org/D10829 llvm-svn: 241102
2015-06-17CodeGen: Factor out some of the bitset entry creation code. NFC.Peter Collingbourne1-18/+4
llvm-svn: 239927
2015-05-09Revert r236879, "Do not emit thunks with available_externally linkage in ↵NAKAMURA Takumi1-1/+3
comdats" It broke pecoff, at least i686-cygwin. llvm-svn: 236937
2015-05-08Do not emit thunks with available_externally linkage in comdatsDerek Schuff1-3/+1
Functions with available_externally linkage will not be emitted to object files (they will just be undefined symbols), so it does not make sense to put them in comdats. Creates a second overload of maybeSetTrivialComdat that uses the GlobalObject instead of the Decl, and uses that in several places that had the faulty logic. Differential Revision: http://reviews.llvm.org/D9580 llvm-svn: 236879
2015-04-02Implement CFI type checks for non-virtual calls.Peter Collingbourne1-1/+4
This uses the same class metadata currently used for virtual call and cast checks. The new flag is -fsanitize=cfi-nvcall. For consistency, the -fsanitize=cfi-vptr flag has been renamed -fsanitize=cfi-vcall. Differential Revision: http://reviews.llvm.org/D8756 llvm-svn: 233874
2015-03-18MS ABI: Don't try to emit VF/VB-Tables for extern class templatesDavid Majnemer1-1/+1
There will be an explicit template instantiation in another translation unit which will provide the definition of the VF/VB-Tables. This fixes PR22932. llvm-svn: 232680
2015-02-24CodeGenModule::EmitVTableBitSetEntries: Add check for identical bit set entries.Peter Collingbourne1-0/+3
No two elements of this array should be the same, but the standard library may pass the same element as both arguments to this function. llvm-svn: 230293
2015-02-20Implement Control Flow Integrity for virtual calls.Peter Collingbourne1-0/+61
This patch introduces the -fsanitize=cfi-vptr flag, which enables a control flow integrity scheme that checks that virtual calls take place using a vptr of the correct dynamic type. More details in the new docs/ControlFlowIntegrity.rst file. It also introduces the -fsanitize=cfi flag, which is currently a synonym for -fsanitize=cfi-vptr, but will eventually cover all CFI checks implemented in Clang. Differential Revision: http://reviews.llvm.org/D7424 llvm-svn: 230055
2015-01-19Add comdat to thunks.Rafael Espindola1-1/+4
llvm-svn: 226465
2015-01-15Remove ASTConsumer::HandleVTable()'s bool parameter.Nico Weber1-12/+6
Sema calls HandleVTable() with a bool parameter which is then threaded through three layers. The only effect of this bool is an early return at the last layer. Instead, remove this parameter and call HandleVTable() only if the bool is true. No intended behavior change. llvm-svn: 226096
2014-12-29PR22051: Missing debug location on calls in dtor thunks in Windows.David Blaikie1-1/+1
llvm-svn: 224963
2014-12-29Use std::find_if instead of manual loop.David Blaikie1-8/+4
llvm-svn: 224960
2014-11-01CodeGen: Virtual dtor thunks shouldn't have this marked as 'returned'David Majnemer1-1/+1
The ARM ABI virtual destructor thunks cannot be marked as 'returned' because they return undef. llvm-svn: 221042
2014-10-31MS ABI: Properly call global delete when invoking virtual destructorsDavid Majnemer1-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
2014-10-23Don't emit strong vtable definitions for imported classes with key functions ↵Hans Wennborg1-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
2014-08-13Simplify a few loops over CallArgList/FunctionArgList. NFCAlexey Samsonov1-4/+1
llvm-svn: 215571
2014-07-26MS ABI: Use musttail for vtable thunks that pass arguments by valueReid Kleckner1-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
2014-07-26Remove an extra parameter and C++11 for loop-ify this codeReid Kleckner1-9/+7
llvm-svn: 214003
2014-07-25MS ABI: Don't push destructor cleanups for aggregate parameters in thunksReid Kleckner1-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
2014-07-01MS ABI: Reference MSVC RTTI from the VFTableDavid Majnemer1-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
2014-06-06MS ABI: Update the thunk linkage computationHans Wennborg1-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
2014-05-30Start adding support for dllimport/dllexport on classes (PR11170)Hans Wennborg1-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
2014-05-21[C++11] Use 'nullptr'. CodeGen edition.Craig Topper1-10/+10
llvm-svn: 209272
2014-05-08Simplify a few cast<>s.Rafael Espindola1-9/+12
llvm-svn: 208331
2014-04-10Debug info: (Bugfix) Make sure artificial functions like _GLOBAL__I_aAdrian Prantl1-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
2014-03-07Replace OwningPtr with std::unique_ptr.Ahmed Charles1-1/+1
This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279