summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenFunction.h
Commit message (Collapse)AuthorAgeFilesLines
...
* DebugInfo: Correctly identify the location of C++ member initializer list ↵David Blaikie2014-12-091-6/+10
| | | | | | | | | | | | | elements This particularly helps the fidelity of ASan reports (which can occur even in these examples - if, for example, one uses placement new over a buffer of insufficient size - now ASan will correctly identify which member's initialization went over the end of the buffer). This doesn't cover all types of members - more coming. llvm-svn: 223726
* CodeGen: refactor ARM builtin handlingSaleem Abdulrasool2014-12-041-0/+2
| | | | | | | | Create a helper function to construct a value for the ARM hint intrinsic rather than inling the construction. In order to avoid the use of the sentinel value, inline the use of intrinsic instruction retrieval. NFC. llvm-svn: 223338
* Fix incorrect codegen for devirtualized calls to virtual overloaded operators.Nico Weber2014-12-031-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this program: struct A { virtual void operator-() { printf("base\n"); } }; struct B final : public A { virtual void operator-() override { printf("derived\n"); } }; int main() { B* b = new B; -static_cast<A&>(*b); } Before this patch, clang saw the virtual call to A::operator-(), figured out that it can be devirtualized, and then just called A::operator-() directly, without going through the vtable. Instead, it should've looked up which operator-() the call devirtualizes to and should've called that. For regular virtual member calls, clang gets all this right already. So instead of giving EmitCXXOperatorMemberCallee() all the logic that EmitCXXMemberCallExpr() already has, cut the latter function into two pieces, call the second piece EmitCXXMemberOrOperatorMemberCallExpr(), and use it also to generate code for calls to virtual member operators. This way, virtual overloaded operators automatically don't get devirtualized if they have covariant returns (like it was done for regular calls in r218602), etc. This also happens to fix (or at least improve) codegen for explicit constructor calls (`A a; a.A::A()`) in MS mode with -fsanitize-address-field-padding=1. (This adjustment for virtual operator calls seems still wrong with the MS ABI.) llvm-svn: 223185
* Revert "Remove threshold for lifetime marker insertion of named temporaries"Arnaud A. de Grandmaison2014-12-011-3/+0
| | | | | | Revert r222993 while I investigate some MemorySanitizer failures. llvm-svn: 222995
* Remove threshold for lifetime marker insertion of named temporariesArnaud A. de Grandmaison2014-12-011-0/+3
| | | | | | | | | Now that TailRecursionElimination has been fixed with r222354, the threshold on size for lifetime marker insertion can be removed. This only affects named temporary though, as the patch for unnamed temporaries is still in progress. llvm-svn: 222993
* Bundle conditions checked by UBSan with sanitizer kinds they implement.Alexey Samsonov2014-11-111-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This change makes CodeGenFunction::EmitCheck() take several conditions that needs to be checked (all of them need to be true), together with sanitizer kinds these checks are for. This would allow to split one call into UBSan runtime into several calls in case different sanitizer kinds would have different recoverability settings. Tests should be fixed accordingly, I'm working on it. Test Plan: regression test suite. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6219 llvm-svn: 221716
* [Sanitizer] Refactor sanitizer options in LangOptions.Alexey Samsonov2014-11-111-2/+2
| | | | | | | | | | | | | | | | | | Get rid of ugly SanitizerOptions class thrust into LangOptions: * Make SanitizeAddressFieldPadding a regular language option, and rely on default behavior to initialize/reset it. * Make SanitizerBlacklistFile a regular member LangOptions. * Introduce the helper class "SanitizerSet" to represent the set of enabled sanitizers and make it a member of LangOptions. It is exactly the entity we want to cache and modify in CodeGenFunction, for instance. We'd also be able to reuse SanitizerSet in CodeGenOptions for storing the set of recoverable sanitizers, and in the Driver to represent the set of sanitizers turned on/off by the commandline flags. No functionality change. llvm-svn: 221653
* Propagate SanitizerKind into CodeGenFunction::EmitCheck() call.Alexey Samsonov2014-11-101-11/+1
| | | | | | | | | | | | | | | | Make sure CodeGenFunction::EmitCheck() knows which sanitizer it emits check for. Make CheckRecoverableKind enum an implementation detail and move it away from header. Currently CheckRecoverableKind is determined by the type of sanitizer ("unreachable" and "return" are unrecoverable, "vptr" is always-recoverable, all the rest are recoverable). This will change in future if we allow to specify which sanitizers are recoverable, and which are not by -fsanitize-recover= flag. No functionality change. llvm-svn: 221635
* Silence a warning from MSVC "14" by making an enum unsignedReid Kleckner2014-10-311-2/+2
| | | | | | | | | | It says there is a narrowing conversion when we assign it to an unsigned 3 bit bitfield. Also, use unsigned instead of size_t for the Size field of the struct in question. Otherwise they won't run together in MSVC or clang-cl. llvm-svn: 221019
* MS ABI: Properly call global delete when invoking virtual destructorsDavid Majnemer2014-10-311-0/+8
| | | | | | | | | | | | | | | | | | | | 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
* Get rid of SanitizerOptions::Disabled global. NFC.Alexey Samsonov2014-10-301-1/+1
| | | | | | | | | SanitizerOptions is not even a POD now, so having global variable of this type, is not nice. Instead, provide a regular constructor and clear() method, and let each CodeGenFunction has its own copy of SanitizerOptions it uses. llvm-svn: 220920
* Improved capturing variable-length array types in CapturedStmt.Alexey Bataev2014-10-291-1/+2
| | | | | | | | An updated implemnentation of VLA types capturing based on previously committed solution for Lambdas. This version captures the whole VLA type instead of particular variables which are part of VLA size expression and allows to use previusly calculated size of VLA type in captured regions. Required for OpenMP. Differential Revision: http://reviews.llvm.org/D5099 llvm-svn: 220850
* Objective-C. revert patch for rdar://17554063.Fariborz Jahanian2014-10-281-2/+1
| | | | llvm-svn: 220812
* Fixing the MSVC build by removing friendship with CodeGenFunction; NFC.Aaron Ballman2014-10-211-1/+0
| | | | llvm-svn: 220293
* [OPENMP] Codegen for 'private' clause in 'parallel' directive.Alexey Bataev2014-10-211-0/+3
| | | | | | | This patch generates some helper variables which used as a private copies of the corresponding original variables inside an OpenMP 'parallel' directive. These generated variables are initialized by default (with the default constructor, if any). In outlined function references to original variables are replaced by the references to these private helper variables. At the end of the initialization of the private variables and implicit barier is set by calling __kmpc_barrier(...) runtime function to be sure that all threads were initialized using original values of the variables. Differential Revision: http://reviews.llvm.org/D4752 llvm-svn: 220262
* Insert poisoned paddings between fields in C++ classes so that ↵Kostya Serebryany2014-10-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | AddressSanitizer can find intra-object-overflow bugs Summary: The general approach is to add extra paddings after every field in AST/RecordLayoutBuilder.cpp, then add code to CTORs/DTORs that poisons the paddings (CodeGen/CGClass.cpp). Everything is done under the flag -fsanitize-address-field-padding. The blacklist file (-fsanitize-blacklist) allows to avoid the transformation for given classes or source files. See also https://code.google.com/p/address-sanitizer/wiki/IntraObjectOverflow Test Plan: run SPEC2006 and some of the Chromium tests with -fsanitize-address-field-padding Reviewers: samsonov, rnk, rsmith Reviewed By: rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D5687 llvm-svn: 219961
* Moving CGF::EmitAlignmentAssumption to IRBuilderHal Finkel2014-10-151-1/+4
| | | | | | | | The functionality contained in CodeGenFunction::EmitAlignmentAssumption has been moved to IRBuilder (so that it can also be used by LLVM-level code). Remove this now-duplicate implementation in favor of the IRBuilder code. llvm-svn: 219877
* Sanitize upcasts and conversion to virtual base.Alexey Samsonov2014-10-131-3/+10
| | | | | | | | | | | This change adds UBSan check to upcasts. Namely, when we perform derived-to-base conversion, we: 1) check that the pointer-to-derived has suitable alignment and underlying storage, if this pointer is non-null. 2) if vptr-sanitizer is enabled, and we perform conversion to virtual base, we check that pointer-to-derived has a matching vptr. llvm-svn: 219642
* Unfriend CGOpenMPRegionInfo so it can go into an anonymous namespace.Benjamin Kramer2014-10-101-1/+0
| | | | | | Also remove some unnecessary virtual keywords. NFC. llvm-svn: 219497
* Code reformatting and improvement for OpenMP.Alexey Bataev2014-10-101-0/+4
| | | | | | Moved CGOpenMPRegionInfo from CGOpenMPRuntime.h to CGOpenMPRuntime.cpp file and reworked the code for this change. Also added processing of ThreadID variable passed as an argument in outlined functions in parallel and task directives. llvm-svn: 219490
* Code improvements in OpenMP CodeGen.Alexey Bataev2014-10-101-44/+63
| | | | | | This patch makes class OMPPrivateScope a common class for all private variables. Reworked processing of firstprivate variables (now it is based on OMPPrivateScope too). llvm-svn: 219486
* Revert r218865 because it introduced PR21236, a crash in codegen emitting ↵Nick Lewycky2014-10-101-27/+0
| | | | | | the try block. llvm-svn: 219470
* Promote null pointer constants used as arguments to variadic functionsReid Kleckner2014-10-101-1/+3
| | | | | | | | | | | | | | | Make it possible to pass NULL through variadic functions on 64-bit Windows targets. The Visual C++ headers define NULL to 0, when they should define it to 0LL on Win64 so that NULL is a pointer-sized integer. Fixes PR20949. Reviewers: thakis, rsmith Differential Revision: http://reviews.llvm.org/D5480 llvm-svn: 219456
* [OPENMP] 'omp teams' directive basic support.Alexey Bataev2014-10-091-0/+1
| | | | | | Includes parsing and semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive. llvm-svn: 219385
* [OPENMP] Codegen for 'firstprivate' clause.Alexey Bataev2014-10-081-0/+13
| | | | | | | | This patch generates some helper variables that used as private copies of the corresponding original variables inside an OpenMP 'parallel' directive. These generated variables are initialized by copy using values of the original variables (with the copy constructor, if any). For arrays, initializator is generated for single element and in the codegen procedure this initial value is automatically propagated between all elements of the private copy. In outlined function, references to original variables are replaced by the references to these private helper variables. At the end of the initialization of the private variables an implicit barier is generated by calling __kmpc_barrier(...) runtime function to be sure that all threads were initialized using original values of the variables. Differential Revision: http://reviews.llvm.org/D5140 llvm-svn: 219306
* Revert commit r219297.Alexey Bataev2014-10-081-13/+0
| | | | | | Still troubles with OpenMP/parallel_firstprivate_codegen.cpp (now in ARM buildbots). llvm-svn: 219298
* [OPENMP] Codegen for 'firstprivate' clause.Alexey Bataev2014-10-081-0/+13
| | | | | | | | This patch generates some helper variables that used as private copies of the corresponding original variables inside an OpenMP 'parallel' directive. These generated variables are initialized by copy using values of the original variables (with the copy constructor, if any). For arrays, initializator is generated for single element and in the codegen procedure this initial value is automatically propagated between all elements of the private copy. In outlined function, references to original variables are replaced by the references to these private helper variables. At the end of the initialization of the private variables an implicit barier is generated by calling __kmpc_barrier(...) runtime function to be sure that all threads were initialized using original values of the variables. Differential Revision: http://reviews.llvm.org/D5140 llvm-svn: 219297
* Revert back r219295.Alexey Bataev2014-10-081-13/+0
| | | | | | To fix issues with test OpenMP/parallel_firstprivate_codegen.cpp llvm-svn: 219296
* [OPENMP] Codegen for 'firstprivate' clause.Alexey Bataev2014-10-081-0/+13
| | | | | | | | This patch generates some helper variables that used as private copies of the corresponding original variables inside an OpenMP 'parallel' directive. These generated variables are initialized by copy using values of the original variables (with the copy constructor, if any). For arrays, initializator is generated for single element and in the codegen procedure this initial value is automatically propagated between all elements of the private copy. In outlined function, references to original variables are replaced by the references to these private helper variables. At the end of the initialization of the private variables an implicit barier is generated by calling __kmpc_barrier(...) runtime function to be sure that all threads were initialized using original values of the variables. Differential Revision: http://reviews.llvm.org/D5140 llvm-svn: 219295
* Revert "[OPENMP] 'omp teams' directive basic support. Includes parsing and ↵Renato Golin2014-10-081-1/+0
| | | | | | | | | semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive." This reverts commit r219197 because it broke ARM self-hosting buildbots with segmentation fault errors in many tests. llvm-svn: 219289
* Fix IRGen for referencing a static local before emitting its declReid Kleckner2014-10-081-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously CodeGen assumed that static locals were emitted before they could be accessed, which is true for automatic storage duration locals. However, it is possible to have CodeGen emit a nested function that uses a static local before emitting the function that defines the static local, breaking that assumption. Fix it by creating the static local upon access and ensuring that the deferred function body gets emitted. We may not be able to emit the initializer properly from outside the function body, so don't try. Fixes PR18020. See also previous attempts to fix static locals in PR6769 and PR7101. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4787 llvm-svn: 219265
* [OPENMP] 'omp teams' directive basic support.Alexey Bataev2014-10-071-0/+1
| | | | | | Includes parsing and semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive. llvm-svn: 219197
* [OPENMP] Small refactoring of EmitOMPSimdLoop helper routine.Alexander Musman2014-10-071-3/+4
| | | | | | | | | No functional changes intended. Renamed EmitOMPSimdLoop to EmitOMPInnerLoop, I plan to re-use it to emit inner loop in the future patches for CodeGen of the worksharing loop directives (omp for, omp for simd). llvm-svn: 219195
* MS ABI: Implement thread_local for global variablesDavid Majnemer2014-10-051-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This add support for the C++11 feature, thread_local global variables. The ABI Clang implements is an improvement of the MSVC ABI. Sadly, further improvements could be made but not without sacrificing ABI compatibility. The feature is implemented as follows: - All thread_local initialization routines are pointed to from the .CRT$XDU section. - All non-weak thread_local variables have their initialization routines call from a single function instead of getting their own .CRT$XDU section entry. This is done to open up optimization opportunities to the compiler. - All weak thread_local variables have their own .CRT$XDU section entry. This entry is in a COMDAT with the global variable it is initializing; this ensures that we will initialize the global exactly once. - Destructors are registered in the initialization function using __tlregdtor. Differential Revision: http://reviews.llvm.org/D5597 llvm-svn: 219074
* Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison2014-10-021-0/+27
| | | | | | | This will give more information to the optimizers so that they can reuse stack slots and reduce stack usage. llvm-svn: 218865
* [OPENMP] Loop collapsing and codegen for 'omp simd' directive.Alexander Musman2014-10-011-0/+48
| | | | | | | | | | | | | This patch implements collapsing of the loops (in particular, in presense of clause 'collapse'). It calculates number of iterations N and expressions nesessary to calculate the nested loops counters values based on new iteration variable (that goes from 0 to N-1) in Sema. It also adds Codegen for 'omp simd', which uses (and tests) this feature. Differential Revision: http://reviews.llvm.org/D5184 llvm-svn: 218743
* [OPENMP] Parsing/Sema of directive omp parallel for simdAlexander Musman2014-09-231-0/+1
| | | | llvm-svn: 218299
* [OPENMP] Initial parsing/sema analysis of 'target' directive.Alexey Bataev2014-09-191-0/+1
| | | | llvm-svn: 218110
* MS ABI: Don't ICE for pointers to pointers to members of incomplete classesDavid Majnemer2014-09-181-12/+1
| | | | | | | | | | | | | | | | | | | CodeGen would try to come up with an LLVM IR type for a pointer to member type on the way to forming an LLVM IR type for a pointer to pointer to member type. However, if the pointer to member representation has not been locked in yet, we would not be able to come up with a pointer to member IR type. In these cases, make the pointer to member type an incomplete type. This will make the pointer to pointer to member type a pointer to an incomplete type. If the class eventually obtains an inheritance model, we will make the pointer to member type represent the actual inheritance model. Differential Revision: http://reviews.llvm.org/D5373 llvm-svn: 218084
* Parsing/Sema of directive omp for simdAlexander Musman2014-09-181-0/+1
| | | | llvm-svn: 218029
* Implement nonnull-attribute sanitizerAlexey Samsonov2014-09-081-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements a new UBSan check, which verifies that function arguments declared to be nonnull with __attribute__((nonnull)) are actually nonnull in runtime. To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs (where applicable) and if function declaration has nonnull attribute specified for a certain formal parameter, we compare the corresponding RValue to null as soon as it's calculated. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, rnk Differential Revision: http://reviews.llvm.org/D5082 llvm-svn: 217389
* Add __builtin_assume and __builtin_assume_aligned using @llvm.assume.Hal Finkel2014-09-071-0/+4
| | | | | | | | | | | This makes use of the recently-added @llvm.assume intrinsic to implement a __builtin_assume(bool) intrinsic (to provide additional information to the optimizer). This hooks up __assume in MS-compatibility mode to mirror __builtin_assume (the semantics have been intentionally kept compatible), and implements GCC's __builtin_assume_aligned as assume((p - o) & mask == 0). LLVM now contains special logic to deal with assumptions of this form. llvm-svn: 217349
* MS inline asm: Allow __asm blocks to set a return valueReid Kleckner2014-09-041-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | If control falls off the end of a function after an __asm block, MSVC assumes that the inline assembly filled the EAX and possibly EDX registers with an appropriate return value. This functionality is used in inline functions returning 64-bit integers in system headers, so we need some amount of compatibility. This is implemented in Clang by adding extra output constraints to every inline asm block, and storing the resulting output registers into the return value slot. If we see an asm block somewhere in the function body, we emit a normal epilogue instead of marking the end of the function with a return type unreachable. Normal returns in functions not using this functionality will overwrite the return value slot, and in most cases LLVM should be able to eliminate the dead stores. Fixes PR17201. Reviewed By: majnemer Differential Revision: http://reviews.llvm.org/D5177 llvm-svn: 217187
* Kill one of EmitCallArgs overloads. NFC.Alexey Samsonov2014-08-281-46/+33
| | | | llvm-svn: 216635
* Fix some cases were ArrayRefs were being passed by reference.Craig Topper2014-08-271-5/+5
| | | | llvm-svn: 216527
* Pass actual CXXConstructExpr instead of argument iteratorsAlexey Samsonov2014-08-251-2/+1
| | | | | | into EmitSynthesizedCXXCopyCtorCall. No functionality change. llvm-svn: 216410
* Pass actual CallExpr instead of CallExpr-specific iteratorsAlexey Samsonov2014-08-251-9/+5
| | | | | | | | | | | into EmitCXXMemberOrOperatorCall methods. In the end we want to make declaration visible in EmitCallArgs() method, that would allow us to alter CodeGen depending on function/parameter attributes. No functionality change. llvm-svn: 216404
* DebugInfo: Scope for condition variables more narrowly than the loop variable.David Blaikie2014-08-221-1/+1
| | | | | | | | for loops introduce two scopes - one for the outer loop variable and its initialization, and another for the body of the loop, including any variable declared inside the loop condition. llvm-svn: 216288
* CGCall: Factor out the logic mapping call arguments to LLVM IR arguments.Alexey Samsonov2014-08-221-12/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This refactoring introduces ClangToLLVMArgMapping class, which encapsulates the information about the order in which function arguments listed in CGFunctionInfo should be passed to actual LLVM IR function, such as: 1) positions of sret, if there is any 2) position of inalloca argument, if there is any 3) position of helper padding argument for each call argument 4) positions of regular argument (there can be many if it's expanded). Simplify several related methods (ConstructAttributeList, EmitFunctionProlog and EmitCall): now they don't have to maintain iterators over the list of LLVM IR function arguments, dealing with all the sret/inalloca/this complexities, and just use expected positions of LLVM IR arguments stored in ClangToLLVMArgMapping. This may increase the running time of EmitFunctionProlog, as we have to traverse expandable arguments twice, but in further refactoring we will be able to speed up EmitCall by passing already calculated CallArgsToIRArgsMapping to ConstructAttributeList, thus avoiding traversing expandable argument there. No functionality change. Test Plan: regression test suite Reviewers: majnemer, rnk Reviewed By: rnk Subscribers: cfe-commits, rjmccall, timurrrr Differential Revision: http://reviews.llvm.org/D4938 llvm-svn: 216251
* Pass expressions instead of argument ranges to EmitCall/EmitCXXConstructorCall.Alexey Samsonov2014-08-211-12/+5
| | | | | | | | | | | | | | | | | | | | | | | Summary: This is a first small step towards passing generic "Expr" instead of ArgBeg/ArgEnd pair into EmitCallArgs() family of methods. Having "Expr" will allow us to get the corresponding FunctionDecl and its ParmVarDecls, thus allowing us to alter CodeGen depending on the function/parameter attributes. No functionality change. Test Plan: regression test suite Reviewers: rnk Reviewed By: rnk Subscribers: aemerson, cfe-commits Differential Revision: http://reviews.llvm.org/D4915 llvm-svn: 216214
OpenPOWER on IntegriCloud