aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-03-17[Clang] Undef attribute for global variablesJon Chesterfield1-1/+1
Summary: [Clang] Attribute to allow defining undef global variables Initializing global variables is very cheap on hosted implementations. The C semantics of zero initializing globals work very well there. It is not necessarily cheap on freestanding implementations. Where there is no loader available, code must be emitted near the start point to write the appropriate values into memory. At present, external variables can be declared in C++ and definitions provided in assembly (or IR) to achive this effect. This patch provides an attribute in order to remove this reason for writing assembly for performance sensitive freestanding implementations. A close analogue in tree is LDS memory for amdgcn, where the kernel is responsible for initializing the memory after it starts executing on the gpu. Uninitalized variables in LDS are observably cheaper than zero initialized. Patch is loosely based on the cuda __shared__ and opencl __local variable implementation which also produces undef global variables. Reviewers: kcc, rjmccall, rsmith, glider, vitalybuka, pcc, eugenis, vlad.tsyrklevich, jdoerfert, gregrodgers, jfb, aaron.ballman Reviewed By: rjmccall, aaron.ballman Subscribers: Anastasia, aaron.ballman, davidb, Quuxplusone, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D74361
2020-03-09[HIP] Fix device stub nameYaxun (Sam) Liu1-1/+1
HIP emits a device stub function for each kernel in host code. The HIP debugger requires device stub function to have a different unmangled name as the kernel. Currently the name of the device stub function is the mangled name with a postfix .stub. However, this does not work with the HIP debugger since the unmangled name is the same as the kernel. This patch adds prefix __device__stub__ to the unmangled name of the device stub before mangling, therefore the device stub function has a valid mangled name which is different than the device kernel name. The device side kernel name is kept unchanged. kernels with extern "C" also gets the prefix added to the corresponding device stub function. Differential Revision: https://reviews.llvm.org/D68578
2020-02-19[AArch64][SVE] CodeGen of ACLE Builtin TypesSander de Smalen1-2/+5
Summary: This patch adds codegen support for the ACLE builtin types added in: https://reviews.llvm.org/D62960 so that the ACLE builtin types are emitted as corresponding scalable vector types in LLVM. Reviewers: rsandifo-arm, rovka, rjmccall, efriedma Reviewed By: efriedma Subscribers: tschuett, kristof.beyls, hiraditya, rkruppe, psnobl, llvm-commits, cfe-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D74724
2020-02-11[OPENMP50]Full handling of atomic_default_mem_order in requiresAlexey Bataev1-1/+1
directive. According to OpenMP 5.0, The atomic_default_mem_order clause specifies the default memory ordering behavior for atomic constructs that must be provided by an implementation. If the default memory ordering is specified as seq_cst, all atomic constructs on which memory-order-clause is not specified behave as if the seq_cst clause appears. If the default memory ordering is specified as relaxed, all atomic constructs on which memory-order-clause is not specified behave as if the relaxed clause appears. If the default memory ordering is specified as acq_rel, atomic constructs on which memory-order-clause is not specified behave as if the release clause appears if the atomic write or atomic update operation is specified, as if the acquire clause appears if the atomic read operation is specified, and as if the acq_rel clause appears if the atomic captured update operation is specified.
2020-01-30Move verification of Sema::MaximumAlignment to a .cpp fileReid Kleckner1-0/+4
Saves these transitive includes:
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-4/+4
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-19[Concepts] Requires ExpressionsSaar Raz1-0/+1
Implement support for C++2a requires-expressions. Re-commit after compilation failure on some platforms due to alignment issues with PointerIntPair. Differential Revision: https://reviews.llvm.org/D50360
2020-01-18Revert "[Concepts] Requires Expressions"Saar Raz1-1/+0
This reverts commit 027931899763409e2c61a84bdee6057b5e838ffa. There have been some failing tests on some platforms, reverting while investigating.
2020-01-18[Concepts] Requires ExpressionsSaar Raz1-0/+1
Implement support for C++2a requires-expressions. Differential Revision: https://reviews.llvm.org/D50360
2020-01-13[DebugInfo] Add another level to DebugInfoKind called ConstructorAmy Huang1-7/+3
The option will limit debug info by only emitting complete class type information when its constructor is emitted. This patch changes comparisons with LimitedDebugInfo to use the new level instead. Differential Revision: https://reviews.llvm.org/D72427
2020-01-10Only destroy static locals if they have non-trivial destructors.Richard Smith1-1/+2
This fixes a regression introduced in 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 that caused us to emit shutdown-time destruction for variables with ARC ownership, using C++-specific functions that don't exist in C implementations.
2019-12-09Avoid Attr.h includes, CodeGen editionReid Kleckner1-0/+1
This saves around 20 includes of Attr.h. Not much.
2019-12-03[NFC] Pass a reference to CodeGenFunction to methods of LValue andAkira Hatanaka1-18/+18
AggValueSlot This reapplies 8a5b7c35709d9ce1f44a99f0c5b084bf2696ea17 after a null dereference bug in CGOpenMPRuntime::emitUserDefinedMapper. Original commit message: This is needed for the pointer authentication work we plan to do in the near future. https://github.com/apple/llvm-project/blob/a63a81bd9911f87a0b5dcd5bdd7ccdda7124af87/clang/docs/PointerAuthentication.rst
2019-12-03Revert "[NFC] Pass a reference to CodeGenFunction to methods of LValue and"Akira Hatanaka1-18/+18
This reverts commit 8a5b7c35709d9ce1f44a99f0c5b084bf2696ea17. This seems to have broken UBSan because of a null dereference.
2019-12-03[NFC] Pass a reference to CodeGenFunction to methods of LValue andAkira Hatanaka1-18/+18
AggValueSlot This is needed for the pointer authentication work we plan to do in the near future. https://github.com/apple/llvm-project/blob/a63a81bd9911f87a0b5dcd5bdd7ccdda7124af87/clang/docs/PointerAuthentication.rst
2019-11-19[NFC] Refactor representation of materialized temporariesTyker1-0/+1
Summary: this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718 Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: thakis, sammccall, ilya-biryukov, rnkovacs, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69360
2019-11-17Revert "[NFC] Refactor representation of materialized temporaries"Nico Weber1-1/+0
This reverts commit 08ea1ee2db5f9d6460fef1d79d0d1d1a5eb78982. It broke ./ClangdTests/FindExplicitReferencesTest.All on the bots, see comments on https://reviews.llvm.org/D69360
2019-11-16[NFC] Refactor representation of materialized temporariesTyker1-0/+1
Summary: this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718 Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: rnkovacs, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69360
2019-10-15Added support for "#pragma clang section relro=<name>"Dmitry Mikulin1-0/+2
Differential Revision: https://reviews.llvm.org/D68806 llvm-svn: 374934
2019-10-03[Alignment][Clang][NFC] Add CharUnits::getAsAlignGuillaume Chatelet1-4/+4
Summary: This is a prerequisite to removing `llvm::GlobalObject::setAlignment(unsigned)`. This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68274 llvm-svn: 373592
2019-10-03Silence static analyzer getAs<RecordType> null dereference warnings. NFCI.Simon Pilgrim1-1/+1
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<RecordType> directly and if not assert will fire for us. llvm-svn: 373584
2019-09-29For P0784R7: compute whether a variable has constant destruction if itRichard Smith1-11/+4
has a constexpr destructor. For constexpr variables, reject if the variable does not have constant destruction. In all cases, do not emit runtime calls to the destructor for variables with constant destruction. llvm-svn: 373159
2019-08-05[OpenMP 5.0] Codegen support for user-defined mappers.Michael Kruse1-3/+4
This patch implements the code generation for OpenMP 5.0 declare mapper (user-defined mapper) constructs. For each declare mapper, a mapper function is generated. These mapper functions will be called by the runtime and/or other mapper functions to achieve user defined mapping. The design slides can be found at https://github.com/lingda-li/public-sharing/blob/master/mapper_runtime_design.pptx Re-commit after revert in r367773 because r367755 changed the LLVM-IR output such that a CHECK line failed. Patch by Lingda Li <lildmh@gmail.com> Differential Revision: https://reviews.llvm.org/D59474 llvm-svn: 367905
2019-08-04Revert "[OpenMP 5.0] Codegen support for user-defined mappers."Michael Kruse1-4/+3
This reverts commit r367773. The test case OpenMP/declare_mapper_codegen.cpp is failing. llvm-svn: 367774
2019-08-04[OpenMP 5.0] Codegen support for user-defined mappers.Michael Kruse1-3/+4
This patch implements the code generation for OpenMP 5.0 declare mapper (user-defined mapper) constructs. For each declare mapper, a mapper function is generated. These mapper functions will be called by the runtime and/or other mapper functions to achieve user defined mapping. The design slides can be found at https://github.com/lingda-li/public-sharing/blob/master/mapper_runtime_design.pptx Patch by Lingda Li <lildmh@gmail.com> Differential Revision: https://reviews.llvm.org/D59474 llvm-svn: 367773
2019-07-29[DebugInfo] Don't emit incorrect descriptions of thunk params (PR42627)Vedant Kumar1-2/+3
The `this` parameter of a thunk requires adjustment. Stop emitting an incorrect dbg.declare pointing to the unadjusted pointer. We could describe the adjusted value instead, but there may not be much benefit in doing so as users tend not to debug thunks. Robert O'Callahan reports that this matches gcc's behavior. Fixes PR42627. Differential Revision: https://reviews.llvm.org/D65035 llvm-svn: 367269
2019-07-22[OpenCL] Improve destructor support in C++ for OpenCLMarco Antognini1-11/+10
This re-applies r366422 with a fix for Bug PR42665 and a new regression test. llvm-svn: 366670
2019-07-18Revert r366422: [OpenCL] Improve destructor support in C++ for OpenCLIlya Biryukov1-10/+11
Reason: this commit causes crashes in the clang compiler when building LLVM Support with libc++, see https://bugs.llvm.org/show_bug.cgi?id=42665 for details. llvm-svn: 366429
2019-07-18[OpenCL] Improve destructor support in C++ for OpenCLMarco Antognini1-11/+10
Summary: This patch does mainly three things: 1. It fixes a false positive error detection in Sema that is similar to D62156. The error happens when explicitly calling an overloaded destructor for different address spaces. 2. It selects the correct destructor when multiple overloads for address spaces are available. 3. It inserts the expected address space cast when invoking a destructor, if needed, and therefore fixes a crash due to the unmet assertion in llvm::CastInst::Create. The following is a reproducer of the three issues: struct MyType { ~MyType() {} ~MyType() __constant {} }; __constant MyType myGlobal{}; kernel void foo() { myGlobal.~MyType(); // 1 and 2. // 1. error: cannot initialize object parameter of type // '__generic MyType' with an expression of type '__constant MyType' // 2. error: no matching member function for call to '~MyType' } kernel void bar() { // 3. The implicit call to the destructor crashes due to: // Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed. // in llvm::CastInst::Create. MyType myLocal; } The added test depends on D62413 and covers a few more things than the above reproducer. Subscribers: yaxunl, Anastasia, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64569 llvm-svn: 366422
2019-07-16Fix parameter name comments using clang-tidy. NFC.Rui Ueyama1-1/+1
This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
2019-07-10NFC: Pass DataLayout into isBytewiseValueVitaly Buka1-3/+5
Summary: We will need to handle IntToPtr which I will submit in a separate patch as it's not going to be NFC. Reviewers: eugenis, pcc Reviewed By: eugenis Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D63940 llvm-svn: 365709
2019-07-10NFC: Convert large lambda into methodVitaly Buka1-79/+84
Reviewers: pcc, eugenis Reviewed By: eugenis Subscribers: cfe-commits, lldb-commits Tags: #clang, #lldb Differential Revision: https://reviews.llvm.org/D63854 llvm-svn: 365708
2019-07-10[Concepts] Concept definitions (D40381)Saar Raz1-0/+1
First in a series of patches to land C++2a Concepts support. This patch adds AST and parsing support for concept-declarations. llvm-svn: 365699
2019-07-05NFC: Add an explicit return for safety and consistencyHamza Sood1-0/+2
This case implicitly falls-through, which is fine now as it's at the end of the function, but it seems like an accident waiting to happen. llvm-svn: 365210
2019-06-27[NFC] Return early for types with size zeroVitaly Buka1-3/+4
llvm-svn: 364495
2019-06-27[NFC] Remove unneeded local variablesVitaly Buka1-9/+5
llvm-svn: 364492
2019-06-20Rename CodeGenFunction::overlapFor* to getOverlapFor*.Richard Smith1-1/+1
llvm-svn: 363980
2019-06-20Store a pointer to the return value in a static alloca and let the debugger ↵Amy Huang1-4/+11
use that as the variable address for NRVO variables. Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D63361 llvm-svn: 363952
2019-06-14C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue ↵Richard Smith1-30/+50
conversion applied to a member access or similar not-quite-trivial lvalue expression. Summary: When a variable is named in a context where we can't directly emit a reference to it (because we don't know for sure that it's going to be defined, or it's from an enclosing function and not captured, or the reference might not "work" for some reason), we emit a copy of the variable as a global and use that for the known-to-be-read-only access. This reinstates r363295, reverted in r363352, with a fix for PR42276: we now produce a proper name for a non-odr-use reference to a static constexpr data member. The name <mangled-name>.const is used in that case; such names are reserved to the implementation for cases such as this and should demangle nicely. Reviewers: rjmccall Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63157 llvm-svn: 363428
2019-06-14Revert 363295, it caused PR42276. Also revert follow-ups 363337, 363340.Nico Weber1-45/+29
Revert 363340 "Remove unused SK_LValueToRValue initialization step." Revert 363337 "PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type" Revert 363295 "C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression." llvm-svn: 363352
2019-06-13C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue ↵Richard Smith1-29/+45
conversion applied to a member access or similar not-quite-trivial lvalue expression. Summary: When a variable is named in a context where we can't directly emit a reference to it (because we don't know for sure that it's going to be defined, or it's from an enclosing function and not captured, or the reference might not "work" for some reason), we emit a copy of the variable as a global and use that for the known-to-be-read-only access. Reviewers: rjmccall Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63157 llvm-svn: 363295
2019-06-11For DR712: store on a DeclRefExpr whether it constitutes an odr-use.Richard Smith1-2/+2
Begin restructuring to support the forms of non-odr-use reference permitted by DR712. llvm-svn: 363086
2019-04-30Variable auto-init: don't initialize aggregate padding of all aggregatesJF Bastien1-3/+10
Summary: C guarantees that brace-init with fewer initializers than members in the aggregate will initialize the rest of the aggregate as-if it were static initialization. In turn static initialization guarantees that padding is initialized to zero bits. Quoth the Standard: C17 6.7.9 Initialization ❡21 If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration. C17 6.7.9 Initialization ❡10 If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static or thread storage duration is not initialized explicitly, then: * if it has pointer type, it is initialized to a null pointer; * if it has arithmetic type, it is initialized to (positive or unsigned) zero; * if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits; * if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits; <rdar://problem/50188861> Reviewers: glider, pcc, kcc, rjmccall, erik.pilkington Subscribers: jkorous, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61280 llvm-svn: 359628
2019-04-24[Builtins] Implement __builtin_is_constant_evaluated for use in C++2aEric Fiselier1-1/+2
Summary: This patch implements `__builtin_is_constant_evaluated` as specifier by [P0595R2](https://wg21.link/p0595r2). It is built on the back of Bill Wendling's work for `__builtin_constant_p()`. More tests to come, but early feedback is appreciated. I plan to implement warnings for common mis-usages like those belowe in a following patch: ``` void foo(int x) { if constexpr (std::is_constant_evaluated())) { // condition is always `true`. Should use plain `if` instead. foo_constexpr(x); } else { foo_runtime(x); } } ``` Reviewers: rsmith, MaskRay, bruno, void Reviewed By: rsmith Subscribers: dexonsmith, zoecarver, fdeazeve, kristina, cfe-commits Differential Revision: https://reviews.llvm.org/D55500 llvm-svn: 359067
2019-04-12Variable auto-init: also auto-init allocaJF Bastien1-84/+6
Summary: alloca isn’t auto-init’d right now because it’s a different path in clang that all the other stuff we support (it’s a builtin, not an expression). Interestingly, alloca doesn’t have a type (as opposed to even VLA) so we can really only initialize it with memset. <rdar://problem/49794007> Subscribers: jkorous, dexonsmith, cfe-commits, rjmccall, glider, kees, kcc, pcc Tags: #clang Differential Revision: https://reviews.llvm.org/D60548 llvm-svn: 358243
2019-04-03[OPENMP]Add codegen for firstprivate vars with allocate clause.Alexey Bataev1-9/+8
Added codegen/test for the firstprivatized variables with the allocate clause. llvm-svn: 357617
2019-03-19[OPENMP]Remove unused parameter, NFC.Alexey Bataev1-1/+1
Parameter CodeGenModule &CGM is not required for CGOpenMPRuntime member functions, since class holds the reference to the CGM. llvm-svn: 356480
2019-03-16CodeGen: Preserve packed attribute in constStructWithPadding.Peter Collingbourne1-1/+1
Otherwise the object may have an incorrect size due to tail padding. Differential Revision: https://reviews.llvm.org/D59446 llvm-svn: 356328
2019-03-08Variable auto-init: split out small arraysJF Bastien1-22/+38
Summary: Following up with r355181, initialize small arrays as well. LLVM stage2 shows a tiny size gain. <rdar://48523005> Reviewers: glider, pcc, kcc, rjmccall Subscribers: jkorous, dexonsmith, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58885 llvm-svn: 355660
2019-03-07[OPENMP 5.0]Add initial support for 'allocate' directive.Alexey Bataev1-0/+1
Added parsing/sema analysis/serialization/deserialization support for 'allocate' directive. llvm-svn: 355614