aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-03-13[AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (#67999)Zaara Syeda1-0/+1
This patch enables support that the XL compiler had for AIX under -qdatalocal/-qdataimported.
2024-01-18[clang] Add size filter for stack auto init (#74777)Haopeng Liu1-0/+14
Add a clang flag, "-ftrivial-auto-var-init-max-size=" so that clang skips auto-init a variable if the auto-init memset size exceeds the flag setting (in bytes). Note that this skipping doesn't apply to runtime-sized variables like VLA. Considerations: "__attribute__((uninitialized))" can be used to manually opt variables out. However, there are thousands of large variables (e.g., >=1KB, most of them are arrays and used as buffers) in big codebase. Manually opting them out one by one is not efficient.
2023-11-25[clang] Avoid memcopy for small structure with padding under ↵serge-sans-paille1-20/+15
-ftrivial-auto-var-init (#71677) Recommit of 0d2860b795879f4dd152963b52f969b53b136899 with extra test cases fixed.
2023-11-23Revert "[clang] Avoid memcopy for small structure with padding under ↵Florian Hahn1-15/+20
-ftrivial-auto-var-init (#71677)" This reverts commit fe5c360a9aae61db37886c0c795c409b5129905f. The commit causes the tests below to fail on many buildbots, e.g. https://lab.llvm.org/buildbot/#/builders/245/builds/17047 Clang :: CodeGen/aapcs-align.cpp Clang :: CodeGen/aapcs64-align.cpp
2023-11-23[clang] Avoid memcopy for small structure with padding under ↵serge-sans-paille1-20/+15
-ftrivial-auto-var-init (#71677) Recommit of 0d2860b795879f4dd152963b52f969b53b136899 with extra test cases fixed.
2023-11-23Revert "[clang] Avoid memcopy for small structure with padding under ↵Muhammad Omair Javaid1-15/+20
-ftrivial-auto-var-init (#71677)" This reverts commit 0d2860b795879f4dd152963b52f969b53b136899. This change appears to have broken several clang tests on following buildbots: https://lab.llvm.org/buildbot/#/builders/245 https://lab.llvm.org/buildbot/#/builders/188 https://lab.llvm.org/buildbot/#/builders/186 https://lab.llvm.org/buildbot/#/builders/183
2023-11-23[clang] Avoid memcopy for small structure with padding under ↵serge-sans-paille1-20/+15
-ftrivial-auto-var-init (#71677)
2023-11-06[clang][NFC] Refactor `ImplicitParamDecl::ImplicitParamKind`Vlad Serebrennikov1-1/+1
This patch converts `ImplicitParamDecl::ImplicitParamKind` into a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for `preferred_type` annotations on bit-fields.
2023-11-01[clang] Remove no-op ptr-to-ptr bitcasts (NFC)Youngsuk Kim1-3/+1
Opaque pointer cleanup effort.
2023-10-27[clang] Remove no-op ptr-to-ptr bitcasts (NFC)Youngsuk Kim1-2/+0
Opaque pointer cleanup effort. NFC.
2023-10-07[clang] remove ClassScopeFunctionSpecializationDecl (#66636)Krystian Stasiowski1-1/+0
This removes the `ClassScopeFunctionSpecializationDecl` `Decl` node, and instead uses `DependentFunctionTemplateSpecializationInfo` to handle such declarations. `DependentFunctionTemplateSpecializationInfo` is also changed to store a `const ASTTemplateArgumentListInfo*` to be more in line with `FunctionTemplateSpecializationInfo`. This also changes `FunctionDecl::isFunctionTemplateSpecialization` to return `true` for dependent specializations, and `FunctionDecl::getTemplateSpecializationKind`/`FunctionDecl::getTemplateSpecializationKindForInstantiation` to return `TSK_ExplicitSpecialization` for non-friend dependent specializations (the same behavior as dependent class scope `ClassTemplateSepcializationDecl` & `VarTemplateSepcializationDecl`).
2023-08-29[DebugInfo] Fix incorrect dbg.declare when nrvo flag is usedNikita Popov1-2/+1
When clang generates an nrvo boolean flag, the dbg.declare for the corresponding variable was incorrectly placed on that flag, rather than the actual variable. Fix this by not overwriting AllocaAddr with the nrvo flag. This started causing verifier errors with D158743. Differential Revision: https://reviews.llvm.org/D158972
2023-08-17[CodeGen] Remove Constant arguments from linkage functions, NFCI.Jonas Hahnfeld1-1/+1
This was unused since commit dd2362a8ba last year. Differential Revision: https://reviews.llvm.org/D156891
2023-08-14Make globals with mutable members non-constant, even in custom sectionsDavid Blaikie1-2/+4
Turned out we were making overly simple assumptions about which sections (& section flags) would be used when emitting a global into a custom section. This lead to sections with read-only flags being used for globals of struct types with mutable members. Fixed by porting the codegen function with the more nuanced handling/checking for mutable members out of codegen for use in the sema code that does this initial checking/mapping to section flags. Differential Revision: https://reviews.llvm.org/D156726
2023-08-09Intrinsics: Add type overload to stacksave and stackstoreMatt Arsenault1-5/+4
This allows use with non-0 address space stacks. llvm_ptr_ty should never be used. This could use some more percolation up through mlir, but this is enough to fix existing tests. https://reviews.llvm.org/D156666
2023-07-15Add option -fkeep-persistent-storage-variables to emit all variables that ↵Zheng Qian1-0/+3
have a persistent storage duration This patch adds a new option -fkeep-persistent-storage-variables to emit all variables that have a persistent storage duration, including global, static and thread-local variables. This could be useful in cases where the presence of all these variables as symbols in the object file are required, so that they can be directly addressed. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D150221
2023-07-10[OpenMP][OMPIRBuilder] Rename IsEmbedded and IsTargetCodegen flagsSergio Afonso1-1/+1
This patch renames the `OpenMPIRBuilderConfig` flags to reduce confusion over their meaning. `IsTargetCodegen` becomes `IsGPU`, whereas `IsEmbedded` becomes `IsTargetDevice`. The `-fopenmp-is-device` compiler option is also renamed to `-fopenmp-is-target-device` and the `omp.is_device` MLIR attribute is renamed to `omp.is_target_device`. Getters and setters of all these renamed properties are also updated accordingly. Many unit tests have been updated to use the new names, but an alias for the `-fopenmp-is-device` option is created so that external programs do not stop working after the name change. `IsGPU` is set when the target triple is AMDGCN or NVIDIA PTX, and it is only valid if `IsTargetDevice` is specified as well. `IsTargetDevice` is set by the `-fopenmp-is-target-device` compiler frontend option, which is only added to the OpenMP device invocation for offloading-enabled programs. Differential Revision: https://reviews.llvm.org/D154591
2023-07-06Enable dynamic-sized VLAs for data sharing in OpenMP offloaded target regions.Doru Bercea1-17/+63
Review: https://reviews.llvm.org/D153883
2023-07-02[clang][CodeGen] Fix global variables initialized with an inheriting ↵Eli Friedman1-1/+4
constructor. For inheriting constructors which have to be emitted inline, we use CodeGenFunction::EmitInlinedInheritingCXXConstructorCall to emit the required code. This code uses EmitParmDecl to emit the "this" argument of the call. EmitParmDecl then helpfully calls llvm::Value::setName to name the parameter... which renames the global variable to "this". To fix the issue, skip the setName call on globals. The renaming still has slightly weird results in other cases (it renames all local variables initialized with an inlined inheriting constructor to "this"), but the result isn't actually wrong in those cases, so I'm just going to leave it for now. Fixes https://github.com/llvm/llvm-project/issues/63618 Differential Revision: https://reviews.llvm.org/D154270
2023-06-18[clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)Youngsuk Kim1-9/+7
* Add `Address::withElementType()` as a replacement for `CGBuilderTy::CreateElementBitCast`. * Partial progress towards replacing `CreateElementBitCast`, as it no longer does what its name suggests. Either replace its uses with `Address::withElementType()`, or remove them if no longer needed. * Remove unused parameter 'Name' of `CreateElementBitCast` Reviewed By: barannikov88, nikic Differential Revision: https://reviews.llvm.org/D153196
2023-06-16[clang] Replace use of Type::getPointerTo() (NFC)Youngsuk Kim1-2/+3
Partial progress towards replacing in-tree uses of `Type::getPointerTo()`. This needs to be done before deprecating the API. Reviewed By: nikic, barannikov88 Differential Revision: https://reviews.llvm.org/D152321
2023-06-09[Clang] Remove typed pointer consistency assertions (NFC)Nikita Popov1-3/+0
These are no-ops with opaque pointers.
2023-03-16Emit const globals with constexpr destructor as constant LLVM valuesHans Wennborg1-4/+8
This follows 2b4fa53 which made Clang not emit destructor calls for such objects. However, they would still not get emitted as constants since CodeGenModule::isTypeConstant() returns false if the destructor is constexpr. This change adds a param to make isTypeConstant() ignore the dtor, allowing the caller to check it instead. Fixes Issue #61212 Differential revision: https://reviews.llvm.org/D145369
2023-02-15[CodeGen] Add a flag to `Address` and `Lvalue` that is used to keepAkira Hatanaka1-2/+4
track of whether the pointer is known not to be null The flag will be used for the arm64e work we plan to upstream in the future (see https://lists.llvm.org/pipermail/llvm-dev/2019-October/136091.html). Currently the flag has no effect on code generation. Differential Revision: https://reviews.llvm.org/D142584
2023-02-01Reland "[codegen] Store address of indirect arguments on the stack"Felipe de Azevedo Piovezan1-1/+16
The commit was reverted due to a regression in debug information of an optimized code test in lldb. This has since been addressed by: 1. rGf753e5be8239: [LiveDebugValues] Allow EntryValue with OP_deref expressions 2. rG055f2f04e658: [mem2reg][debuginfo] Handle op_deref when converting dbg.declare Differential Revision: https://reviews.llvm.org/D141381
2023-01-16Revert "[codegen] Store address of indirect arguments on the stack"Felipe de Azevedo Piovezan1-16/+1
This reverts commit 7e4447a17db4a070f01c8f8a87505a4b2a1b0e3a.
2023-01-16[codegen] Store address of indirect arguments on the stackFelipe de Azevedo Piovezan1-1/+16
With codegen prior to this patch, truly indirect arguments -- i.e. those that are not `byval` -- can have their debug information lost even at O0. Because indirect arguments are passed by pointer, and this pointer is likely placed in a register as per the function call ABI, debug information is lost as soon as the register gets clobbered. This patch solves the issue by storing the address of the parameter on the stack, using a similar strategy employed when C++ references are passed. In other words, this patch changes codegen from: ``` define @foo(ptr %arg) { call void @llvm.dbg.declare(%arg, [...], metadata !DIExpression()) ``` To: ``` define @foo(ptr %arg) { %ptr_storage = alloca ptr store ptr %arg, ptr %ptr_storage call void @llvm.dbg.declare(%ptr_storage, [...], metadata !DIExpression(DW_OP_deref)) ``` Some common cases where this may happen with C or C++ function calls: 1. "Big enough" trivial structures passed by value under the ARM ABI. 2. Structures that are non-trivial for the purposes of call (as per the Itanium ABI) when passed by value. A few tests were matching the wrong alloca (matching against the new alloca, instead of the old one), so they were updated to either match both allocas or include a `,` right after the alloca type, to prevent matching against a pointer type. Differential Revision: https://reviews.llvm.org/D141381
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-1/+1
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-16[clang][dataflow] Remove unused argument in getNullabilityDani Ferreira Franco Moura1-2/+2
This change will allow users to call getNullability() without providing an ASTContext. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D140104
2022-12-03[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[clang-repl] Support statements on global scope in incremental mode.Vassil Vassilev1-0/+1
This patch teaches clang to parse statements on the global scope to allow: ``` ./bin/clang-repl clang-repl> int i = 12; clang-repl> ++i; clang-repl> extern "C" int printf(const char*,...); clang-repl> printf("%d\n", i); 13 clang-repl> %quit ``` Generally, disambiguating between statements and declarations is a non-trivial task for a C++ parser. The challenge is to allow both standard C++ to be translated as if this patch does not exist and in the cases where the user typed a statement to be executed as if it were in a function body. Clang's Parser does pretty well in disambiguating between declarations and expressions. We have added DisambiguatingWithExpression flag which allows us to preserve the existing and optimized behavior where needed and implement the extra rules for disambiguating. Only few cases require additional attention: * Constructors/destructors -- Parser::isConstructorDeclarator was used in to disambiguate between ctor-looking declarations and statements on the global scope(eg. `Ns::f()`). * The template keyword -- the template keyword can appear in both declarations and statements. This patch considers the template keyword to be a declaration starter which breaks a few cases in incremental mode which will be tackled later. * The inline (and similar) keyword -- looking at the first token in many cases allows us to classify what is a declaration. * Other language keywords and specifiers -- ObjC/ObjC++/OpenCL/OpenMP rely on pragmas or special tokens which will be handled in subsequent patches. The patch conceptually models a "top-level" statement into a TopLevelStmtDecl. The TopLevelStmtDecl is lowered into a void function with no arguments. We attach this function to the global initializer list to execute the statement blocks in the correct order. Differential revision: https://reviews.llvm.org/D127284
2022-10-24"Reapply "GH58368: Correct concept checking in a lambda defined in concept""Erich Keane1-0/+1
This reverts commit cecc9a92cfca71c1b6c2a35c5e302ab649496d11. The problem ended up being how we were handling the lambda-context in code generation: we were assuming any decl context here would be a named-decl, but that isn't the case. Instead, we just replace it with the concept's owning context. Differential Revision: https://reviews.llvm.org/D136451
2022-10-24Revert "Reapply "GH58368: Correct concept checking in a lambda defined in ↵Erich Keane1-1/+0
concept""" This reverts commit b876f6e2f28779211a829d7d4e841fe68885ae20. Still getting build failures on PPC AIX that aren't obvious what is causing them, so reverting while I try to figure this out.
2022-10-24Reapply "GH58368: Correct concept checking in a lambda defined in concept""Erich Keane1-0/+1
This reverts commit 52930162870fee52d0d9c07c5d66e5dce32b08e8. Now with updating the ASTBitcodes to show that this AST is incompatible from the last.
2022-10-24Revert "GH58368: Correct concept checking in a lambda defined in concept"Erich Keane1-1/+0
This reverts commit b7c922607c5ba93db8b893d4ba461052af8317b5. This seems to cause some problems with some modules related things, which makes me think I should have updated the version-major in ast-bit-codes? Going to revert to confirm this was a problem, then change that and re-try a commit.
2022-10-24GH58368: Correct concept checking in a lambda defined in conceptErich Keane1-0/+1
As that bug reports, the problem here is that the lambda's 'context-decl' was not set to the concept, and the lambda picked up template arguments from the concept. SO, we failed to get the correct template arguments in SemaTemplateInstantiate. However, a Concept Specialization is NOT a decl, its an expression, so we weren't able to put the concept in the decl tree like we needed. This patch introduces a ConceptSpecializationDecl, which is the smallest type possible to use for this purpose, containing only the template arguments. The net memory impliciation of this is turning a trailing-objects into a pointer to a type with trailing-objects, so it should be minor. As future work, we may consider giving this type more responsibility, or figuring out how to better merge duplicates, but as this is just a template-argument collection at the moment, there isn't much value to it. Differential Revision: https://reviews.llvm.org/D136451
2022-10-12[HLSL] CodeGen hlsl cbuffer/tbuffer.Xiang Li1-3/+1
cbuffer A { float a; float b; } will be translated to a global variable. Something like struct CB_Ty { float a; float b; }; CB_Ty A; And all use of a and b will be replaced with A.a and A.b. Only support none-legacy cbuffer layout now. CodeGen for Resource binding will be in separate patch. In the separate patch, resource binding will map the resource information to the global variable. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D130131
2022-09-21[NFC] Fix build error ignored by MSVC.Xiang Li1-0/+3
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2022-06-07[NFC][CodeGen] Rename methodMitch Phillips1-1/+1
Extracted from D84652.
2022-05-26[OpenMP] Use the align clause value from 'omp allocate' for globalsMike Rice1-0/+19
Refactor the code that handles the align clause of 'omp allocate' so it can be used with globals as well as local variables. Differential Revision: https://reviews.llvm.org/D126426
2022-04-23[clang][OpenMP][DebugInfo] Debug support for TLS variables present in OpenMP ↵Alok Kumar Sharma1-1/+7
consruct In case of OpenMP programs, thread local variables can be present in any clause pertaining to OpenMP constructs, as we know that compiler generates artificial functions and in some cases values are passed to those artificial functions thru parameters. For an example, if thread local variable is present in copyin clause (testcase attached with the patch), parameter with same name is generated as parameter to artificial function. When user inquires the thread Local variable, its debug info is hidden by the parameter. User never gets the actual TLS variable when inquires it, instead gets the artificial parameter. Current patch suppresses the debug info for such artificial parameter to enable correct debugging of TLS variables. Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D123787
2022-04-15Fix size of flexible array initializers, and re-enable assertions.Eli Friedman1-6/+1
In D123649, I got the formula for getFlexibleArrayInitChars slightly wrong: the flexible array elements can be contained in the tail padding of the struct. Fix the formula to account for that. With the fixed formula, we run into another issue: in some cases, we were emitting extra padding for flexible arrray initializers. Fix CGExprConstant so it uses a packed struct when necessary, to avoid this extra padding. Differential Revision: https://reviews.llvm.org/D123826
2022-04-14Comment out assertions about initializer size added in D123649.Eli Friedman1-0/+5
They're causing failures in LLVM test-suite. Added some regression tests that explain the issue.
2022-04-14Allow flexible array initialization in C++.Eli Friedman1-0/+10
Flexible array initialization is a C/C++ extension implemented in many compilers to allow initializing the flexible array tail of a struct type that contains a flexible array. In clang, this is currently restricted to C. But this construct is used in the Microsoft SDK headers, so I'd like to extend it to C++. For now, this doesn't handle dynamic initialization; probably not hard to implement, but it's extra code, and I don't think it's necessary for the expected uses. And we explicitly fail out of constant evaluation. I've added some additional code to assert that initializers have the correct size, with or without flexible array init. This might catch issues unrelated to flexible array init. Differential Revision: https://reviews.llvm.org/D123649
2022-03-28[Clang] Implement __builtin_source_location.James Y Knight1-0/+1
This builtin returns the address of a global instance of the `std::source_location::__impl` type, which must be defined (with an appropriate shape) before calling the builtin. It will be used to implement std::source_location in libc++ in a future change. The builtin is compatible with GCC's implementation, and libstdc++'s usage. An intentional divergence is that GCC declares the builtin's return type to be `const void*` (for ease-of-implementation reasons), while Clang uses the actual type, `const std::source_location::__impl*`. In order to support this new functionality, I've also added a new 'UnnamedGlobalConstantDecl'. This artificial Decl is modeled after MSGuidDecl, and is used to represent a generic concept of an lvalue constant with global scope, deduplicated by its value. It's possible that MSGuidDecl itself, or some of the other similar sorts of things in Clang might be able to be refactored onto this more-generic concept, but there's enough special-case weirdness in MSGuidDecl that I gave up attempting to share code there, at least for now. Finally, for compatibility with libstdc++'s <source_location> header, I've added a second exception to the "cannot cast from void* to T* in constant evaluation" rule. This seems a bit distasteful, but feels like the best available option. Reviewers: aaron.ballman, erichkeane Differential Revision: https://reviews.llvm.org/D120159
2022-03-17[CodeGen] Avoid some pointer element type accessesNikita Popov1-6/+5
2022-02-17[CodeGen] Rename deprecated Address constructorNikita Popov1-4/+5
To make uses of the deprecated constructor easier to spot, and to ensure that no new uses are introduced, rename it to Address::deprecated(). While doing the rename, I've filled in element types in cases where it was relatively obvious, but we're still left with 135 calls to the deprecated constructor.
2022-02-14[CGBuilder] Remove CreateBitCast() methodNikita Popov1-14/+7
Use CreateElementBitCast() instead, or don't work on Address where not necessary.