aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGClass.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-06-20Prevent devirtualization of calls to un-instantiated functions.Sunil Srivastava1-2/+11
PR 27895 Differential Revision: https://reviews.llvm.org/D22057 llvm-svn: 305862
2017-05-18[CodeGen] Propagate LValueBaseInfo instead of AlignmentSourceKrzysztof Parzyszek1-2/+2
The functions creating LValues propagated information about alignment source. Extend the propagated data to also include information about possible unrestricted aliasing. A new class LValueBaseInfo will contain both AlignmentSource and MayAlias info. This patch should not introduce any functional changes. Differential Revision: https://reviews.llvm.org/D33284 llvm-svn: 303358
2017-02-27PR32042: Create inlined debug info for EmitInlinedInheritingCXXConstructorCall.Adrian Prantl1-1/+3
When clang emits an inheriting C++ constructor it may inline code during the CodeGen phase. This patch ensures that any debug info in this inlined code gets a proper inlined location. Otherwise we can end up with invalid debug info metadata, since all inlined local variables and function arguments would be reparented into the call site. Analogous to ApplyInlineLocation this patch introduces a ApplyInlineDebugLocation scoped helper to facilitate entering an inlined scope and cleaning up afterwards. This fixes one of the issues discovered in PR32042. rdar://problem/30679307 llvm-svn: 296388
2017-02-25C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules ↵Richard Smith1-0/+14
for special member functions. Essentially, as a base class constructor does not construct virtual bases, such a constructor for an abstract class does not need the corresponding base class construction to be valid, and likewise for destructors. This creates an awkward situation: clang will sometimes generate references to the complete object and deleting destructors for an abstract class (it puts them in the construction vtable for a derived class). But we can't generate a "correct" version of these because we can't generate references to base class constructors any more (if they're template specializations, say, we might not have instantiated them and can't assume any other TU will emit a copy). Fortunately, we don't need to, since no correct program can ever invoke them, so instead emit symbols that just trap. We should stop emitting references to these symbols, but still need to emit definitions for compatibility. llvm-svn: 296275
2017-02-24[profiling] PR31992: Don't skip interesting non-base constructorsVedant Kumar1-1/+2
Fix the fact that we don't assign profile counters to constructors in classes with virtual bases, or constructors with variadic parameters. Differential Revision: https://reviews.llvm.org/D30131 llvm-svn: 296062
2017-02-23[CodeGen] Fix ExtParameterInfo bugs in C++ CodeGen code.George Burgess IV1-4/+5
This patch makes use of the prefix/suffix ABI argument distinction that was introduced in r295870, so that we now emit ExtParameterInfo at the correct offset for member calls that have added ABI arguments. I don't see a good way to test the generated param info, since we don't actually seem to use it in CGFunctionInfo outside of Swift. Any suggestions/thoughts for how to better test this are welcome. :) This patch also fixes a small bug with inheriting constructors: if we decide not to pass args into an base class ctor, we would still generate ExtParameterInfo as though we did. The added test-case is for that behavior. llvm-svn: 296024
2017-02-22[CodeGen] Note where we add ABI-specific args in ctors. NFC.George Burgess IV1-4/+5
Meta: The ultimate goal is to teach ExtParameterInfo about pass_object_size attributes. This is necessary for that, since our ExtParameterInfo is a bit buggy in C++. I plan to actually make use of this Prefix/Suffix info in the near future, but I like small single-purpose changes. Especially when those changes are hard to actually test... At the moment, some of our C++-specific CodeGen pretends that ABIs can only add arguments to the beginning of a function call. This isn't quite correct: args can be appended to the end, as well. It hasn't mattered much until now, since we seem to only use this "number of arguments added" data when calculating the ExtParameterInfo to use when making a CGFunctionInfo. Said ExtParameterInfo is currently only used for ParameterABIs (Swift) and ns_consumed (ObjC). So, this patch allows ABIs to indicate whether args they added were at the beginning or end of an argument list. We can use this information to emit ExtParameterInfos more correctly, though like said, that bit is coming soon. No tests since this is theoretically a nop. llvm-svn: 295870
2017-02-17[ubsan] Pass a set of checks to skip to EmitTypeCheck() (NFC)Vedant Kumar1-2/+6
CodeGenFunction::EmitTypeCheck accepts a bool flag which controls whether or not null checks are emitted. Make this a bit more flexible by changing the bool to a SanitizerSet. Needed for an upcoming change which deals with a scenario in which we only want to emit null checks. llvm-svn: 295514
2017-02-02Prevent ICE in dllexport class with _Atomic data memberWarren Ristow1-4/+5
Guard against a null pointer dereference that caused Clang to crash when processing a class containing an _Atomic qualified data member, and that is tagged with 'dllexport'. Differential Revision: https://reviews.llvm.org/D29208 llvm-svn: 293911
2017-02-02CodeGen: add a LLVM_FALLTHROUGH to a fallthrough (NFC)Saleem Abdulrasool1-3/+3
Drive by cleanup noticed while investigating an IR verifier assertion. llvm-svn: 293867
2017-02-01clang-cl: Evaluate arguments left-to-right in constructor call with ↵Hans Wennborg1-1/+5
initializer list (PR31831) clang-cl would evaluate the arguments right-to-left (see PR), and for non-Windows targets I suppose we only got it because we were already emitting left-to-right in CodeGenFunction::EmitCallArgs. Differential Revision: https://reviews.llvm.org/D29350 llvm-svn: 293732
2016-12-14Remove custom handling of array copies in lambda by-value array capture andRichard Smith1-163/+9
copy constructors of classes with array members, instead using ArrayInitLoopExpr to represent the initialization loop. This exposed a bug in the static analyzer where it was unable to differentiate between zero-initialized and unknown array values, which has also been fixed here. llvm-svn: 289618
2016-12-12[clang] Version support for UBSan handlersFilipe Cabecinhas1-3/+3
This adds a way for us to version any UBSan handler by itself. The patch overrides D21289 for a better implementation (we're able to rev up a single handler). After this, then we can land a slight modification of D19667+D19668. We probably don't want to keep all the versions in compiler-rt (maybe we want to deprecate on one release and remove the old handler on the next one?), but with this patch we will loudly fail to compile when mixing incompatible handler calls, instead of silently compiling and then providing bad error messages. Reviewers: kcc, samsonov, rsmith, vsk Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21695 llvm-svn: 289444
2016-11-11PR30937: don't devirtualize if we find that the callee is a pure virtualRichard Smith1-23/+20
function. In that case, there is no requirement that the callee is actually defined, and the code may in fact be valid and have defined behavior if the virtual call is unreachable. llvm-svn: 286534
2016-11-03Improve obvious-most-derived-type devirtualization:Richard Smith1-37/+15
* if the base is produced by a series of derived-to-base conversions, check the expression inside them when looking for an expression with a known dynamic type * step past MaterializeTemporaryExprs when checking for a known dynamic type * when checking for a known dynamic type, treat all class prvalues as having a known dynamic type after skipping all relevant rvalue subobject adjustments * treat callees formed by pointer-to-member access for a non-reference member type like callees formed by member access. llvm-svn: 285954
2016-10-26Refactor call emission to package the function pointer together withJohn McCall1-6/+8
abstract information about the callee. NFC. The goal here is to make it easier to recognize indirect calls and trigger additional logic in certain cases. That logic will come in a later patch; in the meantime, I felt that this was a significant improvement to the code. llvm-svn: 285258
2016-10-20[CodeGen] Devirtualize calls to methods marked final in a derived classVedant Kumar1-7/+15
If we see a virtual method call to Base::foo() but can infer that the object is an instance of Derived, and that 'foo' is marked 'final' in Derived, we can devirtualize the call to Derived::foo(). Differential Revision: https://reviews.llvm.org/D25813 llvm-svn: 284766
2016-07-20When copying an array into a lambda, destroy temporaries fromJohn McCall1-0/+35
the copy-constructor immediately and enter a partial array cleanup for previously-copied elements. Fixes PR28595. llvm-svn: 276180
2016-06-28P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:Richard Smith1-46/+170
Replace inheriting constructors implementation with new approach, voted into C++ last year as a DR against C++11. Instead of synthesizing a set of derived class constructors for each inherited base class constructor, we make the constructors of the base class visible to constructor lookup in the derived class, using the normal rules for using-declarations. For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived class that tracks the requisite additional information. We create shadow constructors (not found by name lookup) in the derived class to model the actual initialization, and have a new expression node, CXXInheritedCtorInitExpr, to model the initialization of a base class from such a constructor. (This initialization is special because it performs real perfect forwarding of arguments.) In cases where argument forwarding is not possible (for inalloca calls, variadic calls, and calls with callee parameter cleanup), the shadow inheriting constructor is not emitted and instead we directly emit the initialization code into the caller of the inherited constructor. Note that this new model is not perfectly compatible with the old model in some corner cases. In particular: * if B inherits a private constructor from A, and C uses that constructor to construct a B, then we previously required that A befriends B and B befriends C, but the new rules require A to befriend C directly, and * if a derived class has its own constructors (and so its implicit default constructor is suppressed), it may still inherit a default constructor from a base class llvm-svn: 274049
2016-06-25CodeGen: Start emitting checked loads when both trapping CFI and ↵Peter Collingbourne1-0/+36
-fwhole-program-vtables are enabled. Differential Revision: http://reviews.llvm.org/D21122 llvm-svn: 273757
2016-06-24CodeGen: Update Clang to use the new type metadata.Peter Collingbourne1-20/+18
Differential Revision: http://reviews.llvm.org/D21054 llvm-svn: 273730
2016-06-24Use more ArrayRefsDavid Majnemer1-2/+2
No functional change is intended, just a small refactoring. llvm-svn: 273647
2016-04-29Implementation of VlA of GNU C++ extension, by Vladimir Yakovlev.Alexey Bataev1-1/+1
This enables GNU C++ extension "Variable length array" by default. Differential Revision: http://reviews.llvm.org/D18823 llvm-svn: 268018
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