summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGVTables.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Update clang for LLVM API change.Peter Collingbourne2016-05-101-3/+1
| | | | llvm-svn: 269111
* Re-apply r267784, r267824 and r267830.Peter Collingbourne2016-04-281-26/+31
| | | | | | I have updated the compiler-rt tests. llvm-svn: 267903
* Revert r267784, r267824 and r267830.Benjamin Kramer2016-04-281-31/+26
| | | | | | | | | | It makes compiler-rt tests fail if the gold plugin is enabled. Revert "Rework interface for bitset-using features to use a notion of LTO visibility." Revert "Driver: only produce CFI -fvisibility= error when compiling." Revert "clang/test/CodeGenCXX/cfi-blacklist.cpp: Exclude ms targets. They would be non-cfi." llvm-svn: 267871
* Rework interface for bitset-using features to use a notion of LTO visibility.Peter Collingbourne2016-04-271-26/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Bitsets, and the compiler features they rely on (vtable opt, CFI), only have visibility within the LTO'd part of the linkage unit. Therefore, only enable these features for classes with hidden LTO visibility. This notion is based on object file visibility or (on Windows) dllimport/dllexport attributes. We provide the [[clang::lto_visibility_public]] attribute to override the compiler's LTO visibility inference in cases where the class is defined in the non-LTO'd part of the linkage unit, or where the ABI supports calling classes derived from abstract base classes with hidden visibility in other linkage units (e.g. COM on Windows). If the cross-DSO CFI mode is enabled, bitset checks are emitted even for classes with public LTO visibility, as that mode uses a separate mechanism to cause bitsets to be exported. This mechanism replaces the whole-program-vtables blacklist, so remove the -fwhole-program-vtables-blacklist flag. Because __declspec(uuid()) now implies [[clang::lto_visibility_public]], the support for the special attr:uuid blacklist entry is removed. Differential Revision: http://reviews.llvm.org/D18635 llvm-svn: 267784
* revert SVN r265702, r265640Saleem Abdulrasool2016-04-081-2/+1
| | | | | | | | | | | Revert the two changes to thread CodeGenOptions into the TargetInfo allocation and to fix the layering violation by moving CodeGenOptions into Basic. Code Generation is arguably not particularly "basic". This addresses Richard's post-commit review comments. This change purely does the mechanical revert and will be followed up with an alternate approach to thread the desired information into TargetInfo. llvm-svn: 265806
* Basic: move CodeGenOptions from FrontendSaleem Abdulrasool2016-04-071-1/+2
| | | | | | | | This is a mechanical move of CodeGenOptions from libFrontend to libBasic. This fixes the layering violation introduced earlier by threading CodeGenOptions into TargetInfo. It should also fix the modules based self-hosting builds. NFC. llvm-svn: 265702
* CodeGen: Mark functions used in vtables as unnamed_addr.Peter Collingbourne2016-03-141-0/+4
| | | | | | | | | | | This marks virtual function declarations, as well as runtime library functions __cxa_pure_virtual, __cxa_deleted_virtual and _purecall, as unnamed_addr. This will allow us to correctly form relative references to them from vtables in the relative vtable ABI. Differential Revision: http://reviews.llvm.org/D18071 llvm-svn: 263464
* Add whole-program vtable optimization feature to Clang.Peter Collingbourne2016-02-241-11/+24
| | | | | | | | | This patch introduces the -fwhole-program-vtables flag, which enables the whole-program vtable optimization feature (D16795) in Clang. Differential Revision: http://reviews.llvm.org/D16821 llvm-svn: 261767
* Revert "Revert r260388 "[MS ABI] Never reference dllimport'd vtables""David Majnemer2016-02-111-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
* Use a consistent spelling for vtables.Eric Christopher2016-01-291-12/+12
| | | | llvm-svn: 259137
* [Driver] Add support for -fno-builtin-foo options.Chad Rosier2016-01-061-2/+2
| | | | | | | Addresses PR4941 and rdar://6756912. http://reviews.llvm.org/D15195 llvm-svn: 256937
* [CUDA] Make vtable construction aware of host/device side of CUDA compilation.Artem Belevich2015-12-171-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
* Cross-DSO control flow integrity (Clang part).Evgeniy Stepanov2015-12-151-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
* CodeGen: Remove implicit ilist iterator conversions, NFCDuncan P. N. Exon Smith2015-11-061-6/+8
| | | | | | | Make ilist iterator conversions explicit in clangCodeGen. Eventually I'll remove them everywhere. llvm-svn: 252358
* Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski2015-09-151-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
* Revert "Generating assumption loads of vptr after ctor call (fixed)"Piotr Padlewski2015-09-101-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
* CFI: Introduce -fsanitize=cfi-icall flag.Peter Collingbourne2015-09-101-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
* Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski2015-09-091-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
* Compute and preserve alignment more faithfully in IR-generation.John McCall2015-09-081-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
* Revert r246214 and r246213Steven Wu2015-08-281-3/+3
| | | | | | These two commits causes llvm LTO bootstrap to hang in ScalarEvolution. llvm-svn: 246282
* Assume loads fix #2Piotr Padlewski2015-08-271-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
* Remove and forbid raw_svector_ostream::flush() calls.Yaron Keren2015-08-131-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
* Mark calls in thunk functions as tail-call optimization candidatesMichael Kuperstein2015-08-061-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
* Rangify for loops, NFC.Yaron Keren2015-08-011-2/+2
| | | | llvm-svn: 243841
* Getting rid of old iterator loopsPiotr Padlewski2015-07-281-8/+4
| | | | llvm-svn: 243431
* Generating available_externally vtables for outline virtual functionsPiotr Padlewski2015-07-241-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
* Set comdat when an available_externally thunk is converted to linkonce_odr.Rafael Espindola2015-07-151-12/+17
| | | | | | Fixes pr24130. llvm-svn: 242293
* CodeGen: Improve CFI type blacklisting mechanism.Peter Collingbourne2015-07-151-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
* Set the linkage before setting the visibility.Rafael Espindola2015-07-131-9/+8
| | | | | | | | | Otherwise the visibility setting code would not know that a given function was available_externally. Fixes PR24097. llvm-svn: 242012
* CFI: Emit correct bit set information if RTTI is disabled under MS ABI.Peter Collingbourne2015-07-091-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
* Remove whitespace from start of line, NFC.Yaron Keren2015-07-021-1/+1
| | | | llvm-svn: 241272
* Fix use-after-free.Peter Collingbourne2015-06-301-3/+6
| | | | llvm-svn: 241121
* CodeGen: Assign an appropriate comdat to thunks.Peter Collingbourne2015-06-301-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
* CodeGen: Factor out some of the bitset entry creation code. NFC.Peter Collingbourne2015-06-171-18/+4
| | | | llvm-svn: 239927
* Revert r236879, "Do not emit thunks with available_externally linkage in ↵NAKAMURA Takumi2015-05-091-1/+3
| | | | | | | | comdats" It broke pecoff, at least i686-cygwin. llvm-svn: 236937
* Do not emit thunks with available_externally linkage in comdatsDerek Schuff2015-05-081-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
* Implement CFI type checks for non-virtual calls.Peter Collingbourne2015-04-021-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
* MS ABI: Don't try to emit VF/VB-Tables for extern class templatesDavid Majnemer2015-03-181-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
* CodeGenModule::EmitVTableBitSetEntries: Add check for identical bit set entries.Peter Collingbourne2015-02-241-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
* Implement Control Flow Integrity for virtual calls.Peter Collingbourne2015-02-201-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
* Add comdat to thunks.Rafael Espindola2015-01-191-1/+4
| | | | llvm-svn: 226465
* Remove ASTConsumer::HandleVTable()'s bool parameter.Nico Weber2015-01-151-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
* 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
OpenPOWER on IntegriCloud