summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
AgeCommit message (Collapse)Author
2023-10-31[clang][NFC] Refactor `ArrayType::ArraySizeModifier`Vlad Serebrennikov
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-17[HIP][Clang][CodeGen] Add CodeGen support for `hipstdpar`Alex Voicu
This patch adds the CodeGen changes needed for enabling HIP parallel algorithm offload on AMDGPU targets. This change relaxes restrictions on what gets emitted on the device path, when compiling in `hipstdpar` mode: 1. Unless a function is explicitly marked `__host__`, it will get emitted, whereas before only `__device__` and `__global__` functions would be emitted; 2. Unsupported builtins are ignored as opposed to being marked as an error, as the decision on their validity is deferred to the `hipstdpar` specific code selection pass; 3. We add a `hipstdpar` specific pass to the opt pipeline, independent of optimisation level: - When compiling for the host, iff the user requested it via the `--hipstdpar-interpose-alloc` flag, we add a pass which replaces canonical allocation / deallocation functions with accelerator aware equivalents. A test to validate that unannotated functions get correctly emitted is added as well. Reviewed by: yaxunl, efriedma Differential Revision: https://reviews.llvm.org/D155850
2023-10-10[C++20] [Modules] Don't emit function bodies which is noinline and av… ↵Chuanqi Xu
(#68501) …ailabl externally A workaround for https://github.com/llvm/llvm-project/issues/60996 As the title suggested, we can avoid emitting available externally functions which is marked as noinline already. Such functions should contribute nothing for optimizations. The update for docs will be sent seperately if this got approved.
2023-10-09[OpenMP] Fix setting visibility on declare target variablesJoseph Huber
Summary: A previous patch changed the logic to force external visibliity on declare target variables. This is because they need to be exported in the dynamic symbol table to be usable as the standard depicts. However, the logic was always setting the visibility to `protected`, which would override some symbols. For example, when calling `libc` functions for CPU offloading. This patch changes the logic to only fire if the variable has hidden visibliity to start with.
2023-10-05[OpenMP] Prevent AMDGPU from overriding visibility on DT_nohost variables ↵Joseph Huber
(#68264) Summary: There's some logic in the AMDGPU target that manually resets the requested visibility of certain variables. This was triggering when we set a constant variable in OpenMP. However, we shouldn't do this for OpenMP when the variable has the `nohost` type. That implies that the variable is not visible to the host and therefore does not need to be visible, so we should respect the original value of it.
2023-10-05[clang] Replace uses of Type::getPointerType (NFC)JOE1994
Opaque pointer clean-up effort
2023-10-02-fsanitize=function: fix MSVC hashing to sugared type (#66816)Matheus Izvekov
Hashing the sugared type instead of the canonical type meant that a simple example like this would always fail under MSVC: ``` static auto l() {} int main() { auto a = l; a(); } ``` `clang --target=x86_64-pc-windows-msvc -fno-exceptions -fsanitize=function -g -O0 -fuse-ld=lld -o test.exe test.cc` produces: ``` test.cc:4:3: runtime error: call to function l through pointer to incorrect function type 'void (*)()' ```
2023-10-02[C++] Implement "Deducing this" (P0847R7)Corentin Jabot
This patch implements P0847R7 (partially), CWG2561 and CWG2653. Reviewed By: aaron.ballman, #clang-language-wg Differential Revision: https://reviews.llvm.org/D140828
2023-10-02[C++20] [Modules] Fix crash when emitting module inits for duplicated modulesChuanqi Xu
Close https://github.com/llvm/llvm-project/issues/67893 The root cause of the crash is an oversight that we missed the point that the same module can be imported multiple times. And we should use `SmallSetVector` instead of `SmallVector` to filter the case.
2023-09-30[clang] Remove uses of llvm::Type::getPointerTo() (NFC)JOE1994
* Remove if its sole use is to support an unnecessary ptr-to-ptr bitcast (remove the bitcast as well) * Replace with use of other APIs. NFC opaque pointer cleanup effort.
2023-09-28[NFC] [C++20] [Modules] Refactor Module::getGlobalModuleFragment and ↵Chuanqi Xu
Module::getPrivateModuleFragment The original implementation of `Module::getGlobalModuleFragment` and `Module::getPrivateModuleFragment` tried to find the global module fragment and the private module fragment by comparing strings, which smells bad. This patch tries to improve this.
2023-09-26[clang] Add -mlarge-data-threshold for x86_64 medium code model (#66839)Arthur Eubanks
Error if not used with x86_64. Warn if not used with the medium code model (can update if other code models end up using this). Set TargetMachine option and add module flag.
2023-09-25[clang][CodeGen] Simplify code based on opaque pointers (#65624)Björn Pettersson
- Update CodeGenTypeCache to use a single union for all pointers in address space zero. - Introduce a UnqualPtrTy in CodeGenTypeCache, and use that (for example instead of llvm::PointerType::getUnqual) in some places. - Drop some redundant bit/pointers casts from ptr to ptr.
2023-09-13Revert "[clang][CodeGen] Emit annotations for function declarations."Benjamin Kramer
This reverts commit c6a33ff49dfb3498dae15c718820ea3d9c19f3cb. Makes clang segfault. // clang t.cc class a; class c { public: [[clang::annotate("")]] c(const c *) {} }; class d { d(const c *, a *, a *); c e; }; d::d(const c *f, a *, a *) : e(f) {}
2023-09-12[clang][CodeGen] Emit annotations for function declarations.Brendan Dahl
Previously, annotations were only emitted for function definitions. With this change annotations are also emitted for declarations. Also, emitting function annotations is now deferred until the end so that the most up to date declaration is used which will have any inherited annotations. Differential Revision: https://reviews.llvm.org/D156172/new/
2023-09-08Reapply "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`"Jan Svoboda
This reapplies ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f, except for a tiny part that was reverted separately: 65331da0032ab4253a4bc0ddcb2da67664bd86a9. That will be reapplied later on, since it turned out to be more involved. This commit is enabled by 5523fefb01c282c4cbcaf6314a9aaf658c6c145f and f0f548a65a215c450d956dbcedb03656449705b9, specifically the part that makes 'clang-tidy/checkers/misc/header-include-cycle.cpp' separator agnostic.
2023-09-06Revert "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`"Jan Svoboda
This reverts commit ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f. The 'clang-tidy/checkers/misc/header-include-cycle.cpp' test started failing on Windows: https://lab.llvm.org/buildbot/#/builders/216/builds/26855.
2023-09-06[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`Jan Svoboda
This commit replaces some calls to the deprecated `FileEntry::getName()` with `FileEntryRef::getName()` by swapping current usages of `SourceManager::getFileEntryForID()` with `SourceManager::getFileEntryRefForID()`. This lowers the number of usages of the deprecated `FileEntry::getName()` from 95 to 50.
2023-09-01[CodeGen] First check the kind and then the llvm::Function properties.Vassil Vassilev
This patch fixes valgrind reports from downstream consumers about conditional jump over uninitialised memory. The original report: ```[ RUN ] ScopeReflectionTest.IsComplete ==987150== Conditional jump or move depends on uninitialised value(s) ==987150== at 0x1E1128F: clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition(clang::Decl const*, llvm::Function*) (CodeGenModule.cpp:2391) ==987150== by 0x1E4F181: clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (CodeGenModule.cpp:5669) ==987150== by 0x1E4A194: clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (CodeGenModule.cpp:3909) ==987150== by 0x1E4A752: clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (CodeGenModule.cpp:3649) ==987150== by 0x1E532F5: clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) [clone .part.0] (CodeGenModule.cpp:6563) ==987150== by 0x1B0BEDD: (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (ModuleBuilder.cpp:190) ==987150== by 0x1AEA47B: clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (CodeGenAction.cpp:235) ==987150== by 0x101B02F: clang::IncrementalASTConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (IncrementalParser.cpp:52) ==987150== by 0x101ED93: clang::IncrementalParser::ParseOrWrapTopLevelDecl() (IncrementalParser.cpp:276) ==987150== by 0x101FBBC: clang::IncrementalParser::Parse(llvm::StringRef) (IncrementalParser.cpp:342) ==987150== by 0x100E104: clang::Interpreter::Parse(llvm::StringRef) (Interpreter.cpp:360) ==987150== by 0xE734C0: Cpp::Interpreter::Parse(llvm::StringRef) (CppInterOpInterpreter.h:172) ==987150== Uninitialised value was created by a heap allocation ==987150== at 0x844BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==987150== by 0x1B0C882: StartModule (ModuleBuilder.cpp:139) ==987150== by 0x1B0C882: clang::CodeGenerator::StartModule(llvm::StringRef, llvm::LLVMContext&) (ModuleBuilder.cpp:360) ==987150== by 0x101C4AF: clang::IncrementalParser::GenModule() (IncrementalParser.cpp:372) ==987150== by 0x101FC0E: clang::IncrementalParser::Parse(llvm::StringRef) (IncrementalParser.cpp:362) ==987150== by 0x100E104: clang::Interpreter::Parse(llvm::StringRef) (Interpreter.cpp:360) ==987150== by 0x100E243: clang::Interpreter::create(std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance> >) (Interpreter.cpp:279) ==987150== by 0xF2131A: compat::createClangInterpreter(std::vector<char const*, std::allocator<char const*> >&) (Compatibility.h:123) ==987150== by 0xF22AB9: Cpp::Interpreter::Interpreter(int, char const* const*, char const*, std::vector<std::shared_ptr<clang::ModuleFileExtension>, std::allocator<std::shared_ptr<clang::ModuleFileExtension> > > const&, void*, bool) (CppInterOpInterpreter.h:146) ==987150== by 0xF1827A: CreateInterpreter (CppInterOp.cpp:2494) ==987150== by 0xECFA0E: TestUtils::GetAllTopLevelDecls(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<clang::Decl*, std::allocator<clang::Decl*> >&, bool) (Utils.cpp:23) ==987150== by 0xE9CB85: ScopeReflectionTest_IsComplete_Test::TestBody() (ScopeReflectionTest.cpp:71) ==987150== by 0xF0ED0C: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/vvassilev/workspace/builds/scratch/cppyy/InterOp/build-with-clang-repl-release/unittests/CppInterOp/CppInterOpTests) ==987150== ``` Differential revision: https://reviews.llvm.org/D159339
2023-09-01[clang] [MinGW] Add the option -fno-auto-importMartin Storsjö
In GCC, the .refptr stubs are only generated for x86_64, and only for code models medium and larger (and medium is the default for x86_64 since this was introduced). They can be omitted for projects that are conscious about performance and size, and don't need automatically importing dll data members, by passing -mcmodel=small. In Clang/LLVM, such .refptr stubs are generated for any potentially symbol reference that might end up autoimported. The .refptr stubs are emitted for three separate reasons: - Without .refptr stubs, undefined symbols are mostly referenced with 32 bit wide relocations. If the symbol ends up autoimported from a different DLL, a 32 bit relative offset might not be enough to reference data in a different DLL, depending on runtime loader layout. - Without .refptr stubs, the runtime pseudo relocation mechanism will need to temporarily make sections read-write-executable if there are such relocations in the text section - On ARM and AArch64, the immediate addressing encoded into instructions isn't in the form of a plain 32 bit relative offset, but is expressed with various bits scattered throughout two instructions - the mingw runtime pseudo relocation mechanism doesn't support updating offsets in that form. If autoimporting is known not to be needed, the user can now compile with -fno-auto-import, avoiding the extra overhead of the .refptr stubs. However, omitting them is potentially fragile as the code might still rely on automatically importing some symbol without the developer knowing. If this happens, linking still usually will succeed, but users may encounter issues at runtime. Therefore, if the new option -fno-auto-import is passed to the compiler when driving linking, it passes the flag --disable-auto-import to the linker, making sure that no symbols actually are autoimported when the generated code doesn't expect it. Differential Revision: https://reviews.llvm.org/D61670
2023-08-31[XCOFF][AIX] Issue an error when specifying an alias for a common symbolStephen Peckham
Summary: There is no support in XCOFF for labels on common symbols. Therefore, an alias for a common symbol is not supported. Issue an error in the front end when an aliasee is a common symbol. Issue a similar error in the back end in case an IR specifies an alias for a common symbol. Reviewed by: hubert.reinterpretcast, DiggerLin Differential Revision: https://reviews.llvm.org/D158739
2023-08-30[CodeGen] Function multi-versioning: don't set comdat for internal linkage ↵Fangrui Song
resolvers For function multi-versioning using the target or target_clones function attributes, currently we incorrectly set comdat for internal linkage resolvers. This is problematic for ELF linkers as GRP_COMDAT deduplication will kick in even with STB_LOCAL signature (https://groups.google.com/g/generic-abi/c/2X6mR-s2zoc "GRP_COMDAT group with STB_LOCAL signature"). In short, two `__attribute((target_clones(...))) static void foo()` in two translation units will be deduplicated. Fix this. Fix #65114 Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D158963
2023-08-30[NFC] Remove unused variables declared in conditionsTakuya Shimizu
D152495 makes clang warn on unused variables that are declared in conditions like `if (int var = init) {}` This patch is an NFC fix to suppress the new warning in llvm,clang,lld builds to pass CI in the above patch. Differential Revision: https://reviews.llvm.org/D158016
2023-08-29[OpenMP][DeviceRTL][AMDGPU] Support code object version 5Saiyedul Islam
Update DeviceRTL and the AMDGPU plugin to support code object version 5. Default is code object version 4. CodeGen for __builtin_amdgpu_workgroup_size generates code for cov4 as well as cov5 if -mcode-object-version=none is specified. DeviceRTL compilation passes this argument via Xclang option to generate abi-agnostic code. Generated code for the above builtin uses a clang control constant "llvm.amdgcn.abi.version" to branch on the abi version, which is available during linking of user's OpenMP code. Load of this constant gets eliminated during linking. AMDGPU plugin queries the ELF for code object version and then prepares various implicitargs accordingly. Differential Revision: https://reviews.llvm.org/D139730 Reviewed By: jhuber6, yaxunl
2023-08-28[MSABI] Remove comdat attribute for inheriting ctor.Jennifer Yu
Currently, for MS, the linkage for the inheriting constructors is set to internal. However, the comdat attribute is also set like: define internal noundef ptr @"??0?$B@_N@@qeaa@AEBVF@@aebua@@@z"(ptr noundef nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr comdat This could cause linker to fail. The change is to remove comdat attribute for the inheriting constructor to make linker happy. Differential Revision: https://reviews.llvm.org/D158538
2023-08-25[X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}Fangrui Song
GCC 12 (https://gcc.gnu.org/PR101696) allows __builtin_cpu_supports("x86-64") (and -v2 -v3 -v4). This patch ports the feature. * Add `FEATURE_X86_64_{BASELINE,V2,V3,V4}` to enum ProcessorFeatures, but keep CPU_FEATURE_MAX unchanged to make FeatureInfos/FeatureInfos_WithPLUS happy. * Change validateCpuSupports to allow `x86-64{,-v2,-v3,-v4}` * Change getCpuSupportsMask to return `std::array<uint32_t, 4>` where `x86-64{,-v2,-v3,-v4}` set bits `FEATURE_X86_64_{BASELINE,V2,V3,V4}`. * `target("x86-64")` and `cpu_dispatch(x86_64)` are invalid. Tested by commit 9de3b35ac9159d5bae6e6796cb91e4f877a07189 Close https://github.com/llvm/llvm-project/issues/59961 Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D158811
2023-08-24[OpenMP] Emit offloading entries for indirect target variablesJoseph Huber
OpenMP 5.1 allows emission of the `indirect` clause on declare target functions, see https://www.openmp.org/spec-html/5.1/openmpsu70.html#x98-1080002.14.7. The intended use of this is to permit calling device functions via their associated host pointer. In order to do this the first step will be building a map associating these variables. Doing this will require the same offloading entry handling we use for other kernels and globals. We intentionally emit a new global on the device side. Although it's possible to look up the device function's address directly, this would require changing the visibility and would prevent us from making static functions indirect. Also, the CUDA toolchain will optimize out unused functions and using a global prevents that. The downside is that the runtime will need to read the global and copy its value, but there shouldn't be any other costs. Note that this patch just performs the codegen, currently this new offloading entry type is unused and will be ignored by the runtime. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D157738
2023-08-18[CodeGen] Keep track of eagerly emitted globalsJonas Hahnfeld
An inline virtual function must be emitted, but we need to remember it and emit the same definition again in the future in case later LLVM optimizations stripped it from the Module. The added test case shows the problem; before this patch, it would fail with: Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ] This reapplies commit f8dadefd4a, reverted in commit 0e17372b38, but disables RTTI in the test to avoid problems on Windows. Differential Revision: https://reviews.llvm.org/D156537
2023-08-17Revert "[CodeGen] Keep track of eagerly emitted globals"Jonas Hahnfeld
The added test doesn't work on Windows: https://lab.llvm.org/buildbot/#/builders/216/builds/25769 This reverts commit f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328.
2023-08-17[CodeGen] Keep track of eagerly emitted globalsJonas Hahnfeld
An inline virtual function must be emitted, but we need to remember it and emit the same definition again in the future in case later LLVM optimizations stripped it from the Module. The added test case shows the problem; before this patch, it would fail with: Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ] Differential Revision: https://reviews.llvm.org/D156537
2023-08-17[CodeGen] Clean up access to EmittedDeferredDecls, NFCI.Jonas Hahnfeld
GlobalDecls should only be added to EmittedDeferredDecls if they need reemission. This is checked in addEmittedDeferredDecl, which is called via addDeferredDeclToEmit. Extend these checks to also handle VarDecls (for lambdas, as tested in Interpreter/lambda.cpp) and remove the direct access of EmittedDeferredDecls in EmitGlobal that may actually end up duplicating FunctionDecls. Differential Revision: https://reviews.llvm.org/D156897
2023-08-17[CodeGen] Remove Constant arguments from linkage functions, NFCI.Jonas Hahnfeld
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 Blaikie
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-14Disable sanitizer's on ifunc resolvers.Daniel Kiss
Resolvers are running before the module is initialised which leads to crashes due to the santizer is not yet initialised. Fixes #40287 Reviewed By: hctim Differential Revision: https://reviews.llvm.org/D150262
2023-08-10[clang] Drop some references to typed pointers (getInt8PtrTy). NFCBjorn Pettersson
Differential Revision: https://reviews.llvm.org/D157550
2023-08-08[Clang][AArch64] Add/implement ACLE keywords for SME.Sander de Smalen
This patch adds all the language-level function keywords defined in: https://github.com/ARM-software/acle/pull/188 (merged) https://github.com/ARM-software/acle/pull/261 (update after D148700 landed) The keywords are used to control PSTATE.ZA and PSTATE.SM, which are respectively used for enabling the use of the ZA matrix array and Streaming mode. This information needs to be available on call sites, since the use of ZA or streaming mode may have to be enabled or disabled around the call-site (depending on the IR attributes set on the caller and the callee). For calls to functions from a function pointer, there is no IR declaration available, so the IR attributes must be added explicitly to the call-site. With the exception of '__arm_locally_streaming' and '__arm_new_za' the information is part of the function's interface, not just the function definition, and thus needs to be propagated through the FunctionProtoType::ExtProtoInfo. This patch adds the defintions of these keywords, as well as codegen and semantic analysis to ensure conversions between function pointers are valid and that no conflicting keywords are set. For example, '__arm_streaming' and '__arm_streaming_compatible' are mutually exclusive. Differential Revision: https://reviews.llvm.org/D127762
2023-08-03[X86][Regcall] Add an option to respect regcall ABI v.4 in win64&win32Bing1 Yu
Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D155863
2023-07-31[CodeGen] Assert that EmittedDeferredDecls is emptyJonas Hahnfeld
Its contents are transferred into DeferredDecls in Release(), so it should be empty in moveLazyEmissionStates(). This matches the code downstream in Cling. Differential Revision: https://reviews.llvm.org/D156660
2023-07-28Remove private rdar links. NFCAkira Hatanaka
Differential Revision: https://reviews.llvm.org/D156576
2023-07-28[OpenMP] Do not always emit unused extern variablesJoseph Huber
Currently, the precense of the OpenMP target declare metadata requires that we always codegen a global declaration. This is undesirable in the case that we could defer or omit this declaration as is common with unused extern variables. This is important as it allows us, in the runtime, to rely on static linking semantics to omit unused symbols so they are not included when the user links it in. This patch changes the check for always emitting these variables. Because of this we also need to extend this logic to the generation of the offloading entries. This has the result of derring the offload entry generation to the canonical definitoin. So we are effectively assuming whoever owns the storage for this variable will perform that operation. This makes an exception for `link` attributes as those require their own special handling. Let me know if this is sound in the implementation, I do not have the largest view of the standards here. Fixes: https://github.com/llvm/llvm-project/issues/64133 Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D156368
2023-07-25[Support] Change SetVector's default template parameter to SmallVector<*, 0>Fangrui Song
Similar to D156016 for MapVector. This brings back commit fae7b98c221b5b28797f7b56b656b6b819d99f27 with a fix to llvm/unittests/Support/ThreadPool.cpp's `_WIN32` code path.
2023-07-25Revert rGfae7b98c221b5b28797f7b56b656b6b819d99f27 "[Support] Change ↵Simon Pilgrim
SetVector's default template parameter to SmallVector<*, 0>" This is failing on Windows MSVC builds: llvm\unittests\Support\ThreadPool.cpp(380): error C2440: 'return': cannot convert from 'Vector' to 'std::vector<llvm::BitVector,std::allocator<llvm::BitVector>>' with [ Vector=llvm::SmallVector<llvm::BitVector,0> ]
2023-07-25[Support] Change SetVector's default template parameter to SmallVector<*, 0>Fangrui Song
Similar to D156016 for MapVector.
2023-07-24[Clang] Fix consteval propagation for aggregates and defaulted constructorsCorentin Jabot
This patch does a few things: * Fix aggregate initialization. When an aggregate has an initializer that is immediate-escalating, the context in which it is used automatically becomes an immediate function. The wording does that by rpretending an aggregate initialization is itself an invocation which is not really how clang works, so my previous attempt was... wrong. * Fix initialization of defaulted constructors with immediate escalating default member initializers. The wording was silent about that case and I did not handled it fully https://cplusplus.github.io/CWG/issues/2760.html * Fix diagnostics In some cases clang would produce additional and unhelpful diagnostics by listing the invalid references to consteval function that appear in immediate escalating functions Fixes https://github.com/llvm/llvm-project/issues/63742 Reviewed By: aaron.ballman, #clang-language-wg, Fznamznon Differential Revision: https://reviews.llvm.org/D155175
2023-07-22[CodeGen] Stabilize C2/D2 to C1/D1 replacement orderFangrui Song
The conversion iterates over CodeGenModule::Replacements (a StringMap) and replaces C2/D2 and moves C1/D1 ( commit 0196a1d98f8a206259a4b5ce93c21807243af92f in 2013, to make the output look nicer). The iteration order is not guaranteed to be deterministic, and may cause destructors.cpp to exhibit different function orders. Use a MapVector instead. While here, fix an IWYU issue by adding an explicit include, though MapVector is already used in CodeGenModule.h.
2023-07-21Optimize emission of `dynamic_cast` to final classes.Richard Smith
- When the destination is a final class type that does not derive from the source type, the cast always fails and is now emitted as a null pointer or call to __cxa_bad_cast. - When the destination is a final class type that does derive from the source type, emit a direct comparison against the corresponding base class vptr value(s). There may be more than one such value in the case of multiple inheritance; check them all. For now, this is supported only for the Itanium ABI. I expect the same thing is possible for the MS ABI too, but I don't know what guarantees are made about vfptr uniqueness. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D154658
2023-07-20[NFC] Remove needless nullchecks.Sindhu Chittireddy
Differential Revision: https://reviews.llvm.org/D155774
2023-07-19[Clang][CodeGen]`vtable`, `typeinfo` et al. are globalsAlex Voicu
All data structures and values associated with handling virtual functions / inheritance, as well as RTTI, are globals and thus can only reside in the global address space. This was not taken fully taken into account because for most targets, global & generic appear to coincide. However, on targets where global & generic ASes differ (e.g. AMDGPU), this was problematic, since it led to the generation of invalid bitcasts (which would trigger asserts in Debug) and less than optimal code. This patch does two things: ensures that vtables, vptrs, vtts, typeinfo are generated in the right AS, and populated accordingly; removes a bunch of bitcasts which look like left-overs from the typed ptr era. Reviewed By: yxsamliu Differential Revision: https://reviews.llvm.org/D153092
2023-07-17Revert "Remove rdar links; NFC"Mehdi Amini
This reverts commit d618f1c3b12effd0c2bdb7d02108d3551f389d3d. This commit wasn't reviewed ahead of time and significant concerns were raised immediately after it landed. According to our developer policy this warrants immediate revert of the commit. https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy Differential Revision: https://reviews.llvm.org/D155509
2023-07-15Add option -fkeep-persistent-storage-variables to emit all variables that ↵Zheng Qian
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