summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprAgg.cpp
AgeCommit message (Collapse)Author
2023-01-04[clang] Revert parentesized aggregate initalization patchesAlan Zhao
This feature causes clang to crash when compiling Chrome - see https://crbug.com/1405031 and https://github.com/llvm/llvm-project/issues/59675 Revert "[clang] Fix a clang crash on invalid code in C++20 mode." This reverts commit 32d7aae04fdb58e65a952f281ff2f2c3f396d98f. Revert "[clang] Remove overly restrictive aggregate paren init logic" This reverts commit c77a91bb7ba793ec3a6a5da3743ed55056291658. Revert "[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values" This reverts commit 40c52159d3ee337dbed14e4c73b5616ea354c337.
2022-12-21[Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to ↵Shafik Yaghmour
cover anonymous struct in a union GNU extension AggExprEmitter::VisitInitListExpr sanity checks that an empty union is really empty and not a semantic analysis failure. The assert is missing that we allow anonymous structs as a GNU extension. I have updated the assert to take that into account. This fixes: https://github.com/llvm/llvm-project/issues/58800 Differential Revision: https://reviews.llvm.org/D139261
2022-12-14[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a ↵Alan Zhao
parenthesized list of values This patch implements P0960R3, which allows initialization of aggregates via parentheses. As an example: ``` struct S { int i, j; }; S s1(1, 1); int arr1[2](1, 2); ``` This patch also implements P1975R0, which fixes the wording of P0960R3 for single-argument parenthesized lists so that statements like the following are allowed: ``` S s2(1); S s3 = static_cast<S>(1); S s4 = (S)1; int (&&arr2)[] = static_cast<int[]>(1); int (&&arr3)[2] = static_cast<int[2]>(1); ``` This patch was originally authored by @0x59616e and completed by @ayzhao. Fixes #54040, Fixes #54041 Co-authored-by: Sheng <ox59616e@gmail.com> Full write up : https://discourse.llvm.org/t/c-20-rfc-suggestion-desired-regarding-the-implementation-of-p0960r3/63744 Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D129531
2022-11-30[clang][TargetInfo] Use LangAS for getPointer{Width,Align}()Alex Richardson
Mixing LLVM and Clang address spaces can result in subtle bugs, and there is no need for this hook to use the LLVM IR level address spaces. Most of this change is just replacing zero with LangAS::Default, but it also allows us to remove a few calls to getTargetAddressSpace(). This also removes a stale comment+workaround in CGDebugInfo::CreatePointerLikeType(): ASTContext::getTypeSize() does return the expected size for ReferenceType (and handles address spaces). Differential Revision: https://reviews.llvm.org/D138295
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2022-01-27[NFC][Clang][OpaquePtr] Move away from deprecated Address constructor in ↵Arthur Eubanks
VisitArrayInitLoopExpr With this we can bootstrap an `-O0 -g0` clang with `-mllvm -opaque-pointers`!
2021-12-27[CodeGen] Avoid more pointer element type accessesNikita Popov
2021-12-17[CodeGen] Avoid more pointer element type accessesNikita Popov
2021-12-16[CodeGen] Avoid more pointer element type accessesNikita Popov
2021-12-14[CodeGen] Require use of Address::invalid() for invalid address (NFC)Nikita Popov
This no longer allows creating an invalid Address through the regular constructor. There were only two places that did this (AggValueSlot and EHCleanupScope) which did this by converting a potential nullptr into an Address. I've fixed both of these by directly storing an Address instead. This is intended as a bit of preliminary cleanup for D103465. Differential Revision: https://reviews.llvm.org/D115630
2021-11-04No longer crash when a consteval function returns a structureAaron Ballman
Ensure that the destination slot exists in this case. This addresses PR51484.
2021-07-17[OpaquePtr] Remove uses of CreateInBoundsGEP() without element typeNikita Popov
Remove uses of to-be-deprecated API. Unfortunately this one mostly just makes the use of getPointerElementType() explicit, as the correct type to use wasn't immediately available (deriving it from QualType is left as an excercise to the reader).
2021-06-07[Clang][CodeGen] Set the size of llvm.lifetime to unknown for scalable types.Hsiangkai Wang
If the memory object is scalable type, we do not know the exact size of it at compile time. Set the size of lifetime marker to unknown if the object is scalable one. Differential Revision: https://reviews.llvm.org/D102822
2021-04-10[Matrix] Implement C-style explicit type conversions for matrix types.Saurabh Jha
This implements C-style type conversions for matrix types, as specified in clang/docs/MatrixTypes.rst. Fixes PR47141. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D99037
2021-03-10[clang] Don't assert in EmitAggregateCopy on trivial_abi typesArthur Eubanks
Fixes PR42961. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D97872
2020-10-23[CodeGen] Emit destructor calls to destruct non-trivial C structAkira Hatanaka
temporaries created by conditional and assignment operators rdar://problem/64989559 Differential Revision: https://reviews.llvm.org/D83448
2020-10-19Fix MSVC "not all control paths return a value" warning. NFCI.Simon Pilgrim
2020-10-16Make the check for whether we should memset(0) an aggregateRichard Smith
initialization a little smarter. Look through casts that preserve zero-ness when determining if an initializer is zero, so that we can handle cases like an {0} initializer whose corresponding field is a type other than 'int'.
2020-10-16Extend memset-to-zero optimization to C++11 aggregate functional castsRichard Smith
Aggr{...}. We previously missed these cases due to not stepping over the additional AST nodes representing their syntactic form.
2020-10-13[AST] Change return type of getTypeInfoInChars to a proper struct instead of ↵Bevin Hansson
std::pair. Followup to D85191. This changes getTypeInfoInChars to return a TypeInfoChars struct instead of a std::pair of CharUnits. This lets the interface match getTypeInfo more closely. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D86447
2020-10-13[Fixed Point] Add fixed-point to floating point cast types and consteval.Bevin Hansson
Reviewed By: leonardchan Differential Revision: https://reviews.llvm.org/D86631
2020-06-15attempt to fix failing buildbots after 3bab88b7baa20b276faaee0aa7ca87f636c91877Tyker
Prevent IR-gen from emitting consteval declarations Summary: with this patch instead of emitting calls to consteval function. the IR-gen will emit a store of the already computed result.
2020-06-15Revert "Prevent IR-gen from emitting consteval declarations"Kirill Bobyrev
This reverts commit 3bab88b7baa20b276faaee0aa7ca87f636c91877. This patch causes test failures: http://lab.llvm.org:8011/builders/clang-cmake-armv7-quick/builds/17260
2020-06-15Prevent IR-gen from emitting consteval declarationsTyker
Summary: with this patch instead of emitting calls to consteval function. the IR-gen will emit a store of the already computed result. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76420
2020-06-11[CodeGen] Simplify the way lifetime of block captures is extendedAkira Hatanaka
Rather than pushing inactive cleanups for the block captures at the entry of a full expression and activating them during the creation of the block literal, just call pushLifetimeExtendedDestroy to ensure the cleanups are popped at the end of the scope enclosing the block expression. rdar://problem/63996471 Differential Revision: https://reviews.llvm.org/D81624
2020-04-16[CGExprAgg] Fix infinite loop in `findPeephole`Ehud Katz
Simplify the function using IgnoreParenNoopCasts. Fix PR45476 Differential Revision: https://reviews.llvm.org/D78098
2020-03-27[cuda][hip] Add CUDA builtin surface/texture reference support.Michael Liao
Summary: - Re-commit after fix Sema checks on partial template specialization. Reviewers: tra, rjmccall, yaxunl, a.sidorin Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76365
2020-03-27Revert "[cuda][hip] Add CUDA builtin surface/texture reference support."Artem Belevich
This reverts commit 6a9ad5f3f4ac66f0cae592e911f4baeb6ee5eca6. The patch breaks CUDA copmilation. Differential Revision: https://reviews.llvm.org/D76365
2020-03-26[cuda][hip] Add CUDA builtin surface/texture reference support.Michael Liao
Summary: - Even though the bindless surface/texture interfaces are promoted, there are still code using surface/texture references. For example, [PR#26400](https://bugs.llvm.org/show_bug.cgi?id=26400) reports the compilation issue for code using `tex2D` with texture references. For better compatibility, this patch proposes the support of surface/texture references. - Due to the absent documentation and magic headers, it's believed that `nvcc` does use builtins for texture support. From the limited NVVM documentation[^nvvm] and NVPTX backend texture/surface related tests[^test], it's believed that surface/texture references are supported by replacing their reference types, which are annotated with `device_builtin_surface_type`/`device_builtin_texture_type`, with the corresponding handle-like object types, `cudaSurfaceObject_t` or `cudaTextureObject_t`, in the device-side compilation. On the host side, that global handle variables are registered and will be established and updated later when corresponding binding/unbinding APIs are called[^bind]. Surface/texture references are most like device global variables but represented in different types on the host and device sides. - In this patch, the following changes are proposed to support that behavior: + Refine `device_builtin_surface_type` and `device_builtin_texture_type` attributes to be applied on `Type` decl only to check whether a variable is of the surface/texture reference type. + Add hooks in code generation to replace that reference types with the correponding object types as well as all accesses to them. In particular, `nvvm.texsurf.handle.internal` should be used to load object handles from global reference variables[^texsurf] as well as metadata annotations. + Generate host-side registration with proper template argument parsing. --- [^nvvm]: https://docs.nvidia.com/cuda/pdf/NVVM_IR_Specification.pdf [^test]: https://raw.githubusercontent.com/llvm/llvm-project/master/llvm/test/CodeGen/NVPTX/tex-read-cuda.ll [^bind]: See section 3.2.11.1.2 ``Texture reference API` in [CUDA C Programming Guide](https://docs.nvidia.com/cuda/pdf/CUDA_C_Programming_Guide.pdf). [^texsurf]: According to NVVM IR, `nvvm.texsurf.handle` should be used. But, the current backend doesn't have that supported. We may revise that later. Reviewers: tra, rjmccall, yaxunl, a.sidorin Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76365
2020-03-20[CodeGen] Emit destructor calls to destruct non-trivial C struct objectsAkira Hatanaka
returned by function calls or loaded from volatile objects rdar://problem/51867864 Differential Revision: https://reviews.llvm.org/D66094
2020-03-10[CodeGen] Emit destructor calls to destruct compound literalsAkira Hatanaka
Fix a bug in IRGen where it wasn't destructing compound literals in C that are ObjC pointer arrays or non-trivial structs. Also diagnose jumps that enter or exit the lifetime of the compound literals. rdar://problem/51867864 Differential Revision: https://reviews.llvm.org/D64464
2019-12-16[c++20] P1959R0: Remove support for std::*_equality.Richard Smith
2019-12-09Avoid Attr.h includes, CodeGen editionReid Kleckner
This saves around 20 includes of Attr.h. Not much.
2019-12-03[NFC] Pass a reference to CodeGenFunction to methods of LValue andAkira Hatanaka
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 Hatanaka
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 Hatanaka
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-28[CodeGen] Fix clang crash on aggregate initialization of array of labelsJohannes Altmanninger
Summary: Fix PR43700 The ConstantEmitter in AggExprEmitter::EmitArrayInit was initialized with the CodeGenFunction set to null, which caused the crash. Also simplify another call, and make the CGF member a const pointer since it is public but only assigned in the constructor. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70302
2019-11-19[NFC] Refactor representation of materialized temporariesTyker
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 Weber
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 temporariesTyker
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-19[c++20] Add CXXRewrittenBinaryOperator to represent a comparisonRichard Smith
operator that is rewritten as a call to multiple other operators. No functionality change yet: nothing creates these expressions. llvm-svn: 375305
2019-10-03[Alignment][Clang][NFC] Add CharUnits::getAsAlignGuillaume Chatelet
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-01CGExprAgg - remove duplicate code. NFCI.Simon Pilgrim
Remove duplicate getAs<> call, avoiding a clang static analyzer null dereference warning. llvm-svn: 373396
2019-07-25Revert "Revert "CodeGen: ensure placeholder instruction for cleanup is created""Saleem Abdulrasool
This reverts commit fd1274fa78cb0fd32cc1fa2e6f5bb8e62d29df19. Add an explicit triple for the test which is pattern matching overly aggressively. llvm-svn: 367055
2019-07-25Revert "CodeGen: ensure placeholder instruction for cleanup is created"JF Bastien
Originally in https://reviews.llvm.org/D64656 Causes bot failures: /home/buildslave/buildslave/clang-cmake-armv8-full/llvm/tools/clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp:20:16: error: CHECK-NEXT: expected string not found in input // CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]]) ^ <stdin>:37:2: note: scanning from here %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1) ^ <stdin>:37:2: note: with "TMP_R" equal to "%1" %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1) ^ <stdin>:37:17: note: possible intended match here %8 = call %struct.R* @_ZN1RC1E1Q(%struct.R* %1) ^ llvm-svn: 367051
2019-07-25CodeGen: ensure placeholder instruction for cleanup is createdSaleem Abdulrasool
A placeholder instruction for use in generation of cleanup code for an initializer list would not be emitted if the base class contained a non-trivial destructor and the class contains no fields of its own. This would be the case when using CTAD to deduce the template arguments for a struct with an overloaded call operator, e.g. ``` template <class... Ts> struct ctad : Ts... {}; template <class... Ts> ctad(Ts...)->ctad<Ts...>; ``` and this class was initialized with a list of lambdas capturing by copy, e.g. ``` ctad c {[s](short){}, [s](long){}}; ``` In a release build the bug would manifest itself as a crash in the SROA pass, however, in a debug build the following assert in CGCleanup.cpp would fail: ``` assert(dominatingIP && "no existing variable and no dominating IP!"); ``` By ensuring that a placeholder instruction is emitted even if there's no fields in the class, neither the assert nor the crash is reproducible. See https://bugs.llvm.org/show_bug.cgi?id=40771 Patch by Øystein Dale! llvm-svn: 367042
2019-07-02[C++2a] Add __builtin_bit_cast, used to implement std::bit_castErik Pilkington
This commit adds a new builtin, __builtin_bit_cast(T, v), which performs a bit_cast from a value v to a type T. This expression can be evaluated at compile time under specific circumstances. The compile time evaluation currently doesn't support bit-fields, but I'm planning on fixing this in a follow up (some of the logic for figuring this out is in CodeGen). I'm also planning follow-ups for supporting some more esoteric types that the constexpr evaluator supports, as well as extending __builtin_memcpy constexpr evaluation to use the same infrastructure. rdar://44987528 Differential revision: https://reviews.llvm.org/D62825 llvm-svn: 364954
2019-06-20Rename CodeGenFunction::overlapFor* to getOverlapFor*.Richard Smith
llvm-svn: 363980
2019-06-20P0840R2: support for [[no_unique_address]] attributeRichard Smith
Summary: Add support for the C++2a [[no_unique_address]] attribute for targets using the Itanium C++ ABI. This depends on D63371. Reviewers: rjmccall, aaron.ballman Subscribers: dschuff, aheejin, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63451 llvm-svn: 363976
2019-06-14PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of typeRichard Smith
nullptr_t does not access memory. We now reuse CK_NullToPointer to represent a conversion from a glvalue of type nullptr_t to a prvalue of nullptr_t where necessary. This reinstates r363337, reverted in r363352. llvm-svn: 363429