aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGClass.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-04-28Re-apply r267784, r267824 and r267830.Peter Collingbourne1-2/+7
I have updated the compiler-rt tests. llvm-svn: 267903
2016-04-28Revert r267784, r267824 and r267830.Benjamin Kramer1-7/+2
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
2016-04-27Rework interface for bitset-using features to use a notion of LTO visibility.Peter Collingbourne1-2/+7
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
2016-04-13[modules] Remove CXX_CTOR_INITIALIZERS_OFFSETS table. Instead of storing an IDRichard Smith1-1/+1
of a table entry in the corresponding decl, store an offset from the current record to the relevant CXX_CTOR_INITIALIZERS record. This results in fewer indirections and a minor .pcm file size reduction. llvm-svn: 266254
2016-04-08revert SVN r265702, r265640Saleem Abdulrasool1-1/+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
2016-04-07Basic: move CodeGenOptions from FrontendSaleem Abdulrasool1-1/+1
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
2016-02-24Add whole-program vtable optimization feature to Clang.Peter Collingbourne1-5/+25
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
2016-02-10Fix some Clang-tidy readability-redundant-control-flow warnings; other minor ↵Eugene Zelenko1-13/+9
fixes. Differential revision: http://reviews.llvm.org/D17060 llvm-svn: 260414
2016-02-09[PGO] Fix issue: explicitly defaulted assignop is not profiledXinliang David Li1-0/+1
Differential Revision: http://reviews.llvm.org/D16947 llvm-svn: 260270
2016-02-03[cfi] Safe handling of unaddressable vtable pointers (clang).Evgeniy Stepanov1-3/+15
Avoid crashing when printing diagnostics for vtable-related CFI errors. In diagnostic mode, the frontend does an additional check of the vtable pointer against the set of all known vtable addresses and lets the runtime handler know if it is safe to inspect the vtable. http://reviews.llvm.org/D16823 llvm-svn: 259716
2016-01-29Use a consistent spelling for vtables.Eric Christopher1-1/+1
llvm-svn: 259137
2016-01-25[cfi] Cross-DSO CFI diagnostic mode (clang part)Evgeniy Stepanov1-10/+13
* Runtime diagnostic data for cfi-icall changed to match the rest of cfi checks * Layout of all CFI diagnostic data changed to put Kind at the beginning. There is no ABI stability promise yet. * Call cfi_slowpath_diag instead of cfi_slowpath when needed. * Emit __cfi_check_fail function, which dispatches a CFI check faliure according to trap/recover settings of the current module. * A tiny driver change to match the way the new handlers are done in compiler-rt. llvm-svn: 258745
2016-01-16Introduce -fsanitize-stats flag.Peter Collingbourne1-0/+17
This is part of a new statistics gathering feature for the sanitizers. See clang/docs/SanitizerStats.rst for further info and docs. Differential Revision: http://reviews.llvm.org/D16175 llvm-svn: 257971
2015-12-15Cross-DSO control flow integrity (Clang part).Evgeniy Stepanov1-6/+13
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-10-06Fix Clang-tidy modernize-use-nullptr warnings in source directories; other ↵Hans Wennborg1-10/+8
minor cleanups Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13406 llvm-svn: 249484
2015-10-02Emiting invariant.group.barrier for ctors bugfixPiotr Padlewski1-10/+11
Ensure that the vptr store in the most-derived constructor is not behind an invariant group barrier. Previously, the base-most vptr store would be the one behind no barrier, and that could result in the creator of the object thinking it had the base-most vtable. This bug caused clang call pure virtual functions when called from constructor body. http://reviews.llvm.org/D13373 llvm-svn: 249197
2015-09-28Generate assume loads only with -fstrict-vtable-pointersPiotr Padlewski1-1/+4
Temporary fix till InstCombine and other possible passes will be efficient to handle multiple assumes. llvm-svn: 248734
2015-09-16CGClass.cpp: Fix a warning in -Asserts. [-Wunused-private-field]NAKAMURA Takumi1-0/+1
llvm-svn: 247778
2015-09-16Implementation and testing for poisoning vtableNaomi Musgrave1-17/+55
ptr in dtor. Summary: After destruction, invocation of virtual functions prevented by poisoning vtable pointer. Reviewers: eugenis, kcc Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D12712 Fixed testing callback emission order to account for vptr. Poison vtable in either complete or base dtor, depending on if virtual bases exist. If virtual bases exist, poison in complete dtor. Otherwise, poison in base. Remove commented-out block. llvm-svn: 247762
2015-09-15Decorating vptr load & stores with !invariant.groupPiotr Padlewski1-6/+18
Adding !invariant.group to vptr load/stores for devirtualization purposes. For more goto: http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html http://reviews.llvm.org/D12026 llvm-svn: 247725
2015-09-15Emiting llvm.invariant.group.barrier when dynamic type changesPiotr Padlewski1-3/+30
For more goto: http://lists.llvm.org/pipermail/cfe-dev/2015-July/044227.html http://reviews.llvm.org/D12312 llvm-svn: 247723
2015-09-15Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski1-47/+86
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-14Revert "Always_inline codegen rewrite" and 2 follow-ups.Evgeniy Stepanov1-1/+1
Revert "Update cxx-irgen.cpp test to allow signext in alwaysinline functions." Revert "[CodeGen] Remove wrapper-free always_inline functions from COMDATs" Revert "Always_inline codegen rewrite." Reason for revert: PR24793. llvm-svn: 247620
2015-09-12Always_inline codegen rewrite.Evgeniy Stepanov1-1/+1
Current implementation may end up emitting an undefined reference for an "inline __attribute__((always_inline))" function by generating an "available_externally alwaysinline" IR function for it and then failing to inline all the calls. This happens when a call to such function is in dead code. As the inliner is an SCC pass, it does not process dead code. Libc++ relies on the compiler never emitting such undefined reference. With this patch, we emit a pair of 1. internal alwaysinline definition (called F.alwaysinline) 2a. A stub F() { musttail call F.alwaysinline } -- or, depending on the linkage -- 2b. A declaration of F. The frontend ensures that F.inlinefunction is only used for direct calls, and the stub is used for everything else (taking the address of the function, really). Declaration (2b) is emitted in the case when "inline" is meant for inlining only (like __gnu_inline__ and some other cases). This approach, among other nice properties, ensures that alwaysinline functions are always internal, making it impossible for a direct call to such function to produce an undefined symbol reference. This patch is based on ideas by Chandler Carruth and Richard Smith. llvm-svn: 247494
2015-09-11Revert "Specify target triple in alwaysinline tests."Evgeniy Stepanov1-1/+1
Revert "Always_inline codegen rewrite." Breaks gdb & lldb tests. Breaks on Fedora 22 x86_64. llvm-svn: 247491
2015-09-11Always_inline codegen rewrite.Evgeniy Stepanov1-1/+1
Current implementation may end up emitting an undefined reference for an "inline __attribute__((always_inline))" function by generating an "available_externally alwaysinline" IR function for it and then failing to inline all the calls. This happens when a call to such function is in dead code. As the inliner is an SCC pass, it does not process dead code. Libc++ relies on the compiler never emitting such undefined reference. With this patch, we emit a pair of 1. internal alwaysinline definition (called F.alwaysinline) 2a. A stub F() { musttail call F.alwaysinline } -- or, depending on the linkage -- 2b. A declaration of F. The frontend ensures that F.inlinefunction is only used for direct calls, and the stub is used for everything else (taking the address of the function, really). Declaration (2b) is emitted in the case when "inline" is meant for inlining only (like __gnu_inline__ and some other cases). This approach, among other nice properties, ensures that alwaysinline functions are always internal, making it impossible for a direct call to such function to produce an undefined symbol reference. This patch is based on ideas by Chandler Carruth and Richard Smith. llvm-svn: 247465
2015-09-10Revert "Generating assumption loads of vptr after ctor call (fixed)"Piotr Padlewski1-87/+47
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-5/+2
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-47/+87
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-08clangCodeGen: Fix comments. [-Wdocumentation]NAKAMURA Takumi1-1/+1
llvm-svn: 246995
2015-09-08Compute and preserve alignment more faithfully in IR-generation.John McCall1-120/+245
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-09-04Fix a couple of \param(s) in r246815. [-Wdocumentation]NAKAMURA Takumi1-2/+2
llvm-svn: 246838
2015-09-03Refactored dtor sanitizing into EHScopeStackNaomi Musgrave1-59/+112
Summary: Dtor sanitization handled amidst other dtor cleanups, between cleaning bases and fields. Sanitizer call pushed onto stack of cleanup operations. Reviewers: eugenis, kcc Differential Revision: http://reviews.llvm.org/D12022 Refactoring dtor sanitizing emission order. - Support multiple inheritance by poisoning after member destructors are invoked, and before base class destructors are invoked. - Poison for virtual destructor and virtual bases. - Repress dtor aliasing when sanitizing in dtor. - CFE test for dtor aliasing, and repression of aliasing in dtor code generation. - Poison members on field-by-field basis, with collective poisoning of trivial members when possible. - Check msan flags and existence of fields, before dtor sanitizing, and when determining if aliasing is allowed. - Testing sanitizing bit fields. llvm-svn: 246815
2015-08-28Revert r246214 and r246213Steven Wu1-83/+43
These two commits causes llvm LTO bootstrap to hang in ScalarEvolution. llvm-svn: 246282
2015-08-27Assume loads fix #2Piotr Padlewski1-1/+8
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-27Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski1-43/+76
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. http://reviews.llvm.org/D11859 llvm-svn: 246213
2015-08-21Revert "Generating assumption loads of vptr after ctor call (fixed)"Piotr Padlewski1-76/+43
Reverting because of 245721 This reverts commit 552658e2b60543c928030b09cc9b5dfcb40c3f28. llvm-svn: 245727
2015-08-21Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski1-43/+76
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. http://reviews.llvm.org/D11859 llvm-svn: 245721
2015-08-18Devirtualize EHScopeStack::Cleanup's dtor because it's never destroyed ↵David Blaikie1-6/+6
polymorphically llvm-svn: 245378
2015-08-18Revert "Generating assumption loads of vptr after ctor call (fixed)"Justin Bogner1-76/+43
Bootstrap bots were failing: http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_build/6382/ http://bb.pgr.jp/builders/clang-3stage-i686-linux/builds/2969 This reverts r245264. llvm-svn: 245267
2015-08-18Generating assumption loads of vptr after ctor call (fixed)Piotr Padlewski1-43/+76
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. http://reviews.llvm.org/D11859 llvm-svn: 245264
2015-08-18Revert r245257 "Generating assumption loads of vptr after ctor call"Hans Wennborg1-76/+43
It caused PR24479 llvm-svn: 245260
2015-08-17Generating assumption loads of vptr after ctor callPiotr Padlewski1-43/+76
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 http://reviews.llvm.org/D11859 llvm-svn: 245257
2015-08-13Fix previous commit: poison only class members, simpler testsNaomi Musgrave1-7/+32
Summary: Poisoning applied to only class members, and before dtors for base class invoked Implement poisoning of only class members in dtor, as opposed to also poisoning fields inherited from base classes. Members are poisoned only once, by the last dtor for a class. Skip poisoning if class has no fields. Verify emitted code for derived class with virtual destructor sanitizes its members only once. Removed patch file containing extraneous changes. Reviewers: eugenis, kcc Differential Revision: http://reviews.llvm.org/D11951 Simplified test cases for use-after-dtor Summary: Simplified test cases to focus on one feature at time. Tests updated to align with new emission order for sanitizing callback. Reviewers: eugenis, kcc Differential Revision: http://reviews.llvm.org/D12003 llvm-svn: 244933
2015-08-12Revert "Implement poisoning of only class members in dtor, as opposed to ↵Naomi Musgrave1-32/+7
also poisoning fields inherited from base classes." This reverts commit 8dbbf3578a9a5d063232b59e558e5fe46e2cd42c. Rolled back due to buildbot failures on 'ninja check-clang'. llvm-svn: 244820
2015-08-12Implement poisoning of only class members in dtor, as opposed to also ↵Naomi Musgrave1-7/+32
poisoning fields inherited from base classes. Verify emitted code for derived class with virtual destructor sanitizes its members only once. Changed emission order for dtor callback, so only the last dtor for a class emits the sanitizing callback, while ensuring that class members are poisoned before base class destructors are invoked. Skip poisoning of members, if class has no fields. Removed patch file containing extraneous changes. Summary: Poisoning applied to only class members, and before dtors for base class invoked Reviewers: eugenis, kcc Differential Revision: http://reviews.llvm.org/D11951 llvm-svn: 244819
2015-08-03Dtor callback emitted when msan attribute not repressed for this function.Naomi Musgrave1-1/+2
Summary: In addition to checking compiler flags, the front-end also examines the attributes of the destructor definition to ensure that the SanitizeMemory attribute is attached. Reviewers: eugenis, kcc Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11727 refactored test into new file, revised how function attribute examined modified test to examine default dtor with and without attribute removed attribute check llvm-svn: 243912
2015-07-30Updated test regex and flagsNaomi Musgrave1-2/+2
llvm-svn: 243669
2015-07-30repress tail call optimization when performing use-after-dtor sanitizationNaomi Musgrave1-0/+4
Reviewers: eugenis, kcc Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11613 llvm-svn: 243668
2015-07-21Pass an iterator range to EmitCallArgsDavid Blaikie1-2/+2
llvm-svn: 242824