aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprConstant.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-26[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all ↵Matheus Izvekov1-18/+5
TagDecls (#155463) And make use of those. These changes are split from prior PR #155028, in order to decrease the size of that PR and facilitate review.
2025-08-25[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)Matheus Izvekov1-8/+5
This changes a bunch of places which use getAs<TagType>, including derived types, just to obtain the tag definition. This is preparation for #155028, offloading all the changes that PR used to introduce which don't depend on any new helpers.
2025-08-25[PAC] Fix codegen for polymorphic class variables with consteval ↵Akira Hatanaka1-3/+4
constructors (#154858) Fix a bug in CodeGen where such variables could cause a compilation error or be emitted with an undef initializer when the vtable was signed with address discrimination. rdar://155696134
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-8/+21
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-06-19[CodeGen] Use range-based for loops (NFC) (#144939)Kazu Hirata1-3/+1
2025-06-04[clang] Function type attribute to prevent CFI instrumentation (#135836)PiJoules1-2/+6
This introduces the attribute discussed in https://discourse.llvm.org/t/rfc-function-type-attribute-to-prevent-cfi-instrumentation/85458. The proposed name has been changed from `no_cfi` to `cfi_unchecked_callee` to help differentiate from `no_sanitize("cfi")` more easily. The proposed attribute has the following semantics: 1. Indirect calls to a function type with this attribute will not be instrumented with CFI. That is, the indirect call will not be checked. Note that this only changes the behavior for indirect calls on pointers to function types having this attribute. It does not prevent all indirect function calls for a given type from being checked. 2. All direct references to a function whose type has this attribute will always reference the true function definition rather than an entry in the CFI jump table. 3. When a pointer to a function with this attribute is implicitly cast to a pointer to a function without this attribute, the compiler will give a warning saying this attribute is discarded. This warning can be silenced with an explicit C-style cast or C++ static_cast.
2025-05-09[clang] Add support for `__ptrauth` being applied to integer types (#137580)Oliver Hunt1-0/+4
Allows the __ptrauth qualifier to be applied to pointer sized integer types, updates Sema to ensure trivially copyable, etc correctly handle address discriminated integers, and updates codegen to perform authentication around arithmetic on the types.
2025-05-09clang: Remove dest LangAS argument from performAddrSpaceCast (#138866)Matt Arsenault1-3/+3
It isn't used and is redundant with the result pointer type argument. A more reasonable API would only have LangAS parameters, or IR parameters, not both. Not all values have a meaningful value for this. I'm also not sure why we have this at all, it's not overridden by any targets and further simplification is possible.
2025-04-15[PAC] Add support for __ptrauth type qualifier (#100830)Akira Hatanaka1-3/+20
The qualifier allows programmer to directly control how pointers are signed when they are stored in a particular variable. The qualifier takes three arguments: the signing key, a flag specifying whether address discrimination should be used, and a non-negative integer that is used for additional discrimination. ``` typedef void (*my_callback)(const void*); my_callback __ptrauth(ptrauth_key_process_dependent_code, 1, 0xe27a) callback; ``` Co-Authored-By: John McCall rjmccall@apple.com
2025-03-21[llvm:ir] Add support for constant data exceeding 4GiB (#126481)pzzp1-4/+4
The test file is over 4GiB, which is too big, so I didn’t submit it.
2025-03-11[HLSL] Make memory representation of boolean vectors in HLSL, vectors of ↵Sarah Spall1-1/+4
i32. Add support for boolean swizzling. (#123977) Make the memory representation of boolean vectors in HLSL, vectors of i32. Allow boolean swizzling for boolean vectors in HLSL. Add tests for boolean vectors and boolean vector swizzling. Closes #91639
2025-03-05[Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` ↵Yingwei Zheng1-1/+4
(#128409) It is an alternative to https://github.com/llvm/llvm-project/pull/127525. Close https://github.com/llvm/llvm-project/issues/127475.
2025-02-14[HLSL] Implement HLSL Aggregate splatting (#118992)Sarah Spall1-0/+1
Implement HLSL Aggregate Splat casting that handles splatting for arrays and structs, and vectors if splatting from a vec1. Closes #100609 and Closes #100619 Depends on #118842
2025-02-07[HLSL] Implement HLSL Elementwise casting (excluding splat cases); Re-land ↵Sarah Spall1-0/+1
#118842 (#126258) Implement HLSLElementwiseCast excluding support for splat cases Do not support casting types that contain bitfields. Partly closes https://github.com/llvm/llvm-project/issues/100609 and partly closes https://github.com/llvm/llvm-project/issues/100619 Re-land #118842 after fixing warning as an error, found by a buildbot.
2025-02-06Revert "[HLSL] Implement HLSL Flat casting (excluding splat cases)" (#126149)Sarah Spall1-1/+0
Reverts llvm/llvm-project#118842
2025-02-06[HLSL] Implement HLSL Flat casting (excluding splat cases) (#118842)Sarah Spall1-0/+1
Implement HLSLElementwiseCast excluding support for splat cases Do not support casting types that contain bitfields. Partly closes #100609 and partly closes #100619
2024-10-14Reapply "[clang][CodeGen] Zero init unspecified fields in initializers in C" ↵yabinc1-11/+96
(#109898) (#110051) This reverts commit d50eaac12f0cdfe27e942290942b06889ab12a8c. Also fixes a bug calculating offsets for bit fields in the original patch.
2024-09-24Revert "[clang][CodeGen] Zero init unspecified fields in initializers in C" ↵Eli Friedman1-82/+11
(#109898) Reverts llvm/llvm-project#97121 Causing failures on LNT bots; log shows a crash in ConstStructBuilder::BuildStruct.
2024-09-24[clang][CodeGen] Zero init unspecified fields in initializers in C (#97121)yabinc1-11/+82
When an initializer is provided to a variable, the Linux kernel relied on the compiler to zero-initialize unspecified fields, as clarified in https://www.spinics.net/lists/netdev/msg1007244.html. But clang doesn't guarantee this: 1. For a union type, if an empty initializer is given, clang only initializes bytes for the first field, left bytes for other (larger) fields are marked as undef. Accessing those undef bytes can lead to undefined behaviors. 2. For a union type, if an initializer explicitly sets a field, left bytes for other (larger) fields are marked as undef. 3. When an initializer is given, clang doesn't zero initialize padding. So this patch makes the following change: 1. In C, when an initializer is provided for a variable, zero-initialize undef and padding fields in the initializer. 2. Document the change in LanguageExtensions.rst. As suggested in https://github.com/llvm/llvm-project/issues/78034#issuecomment-2183437928, the change isn't required by C23, but it's standards conforming to do so. Fixes: https://github.com/llvm/llvm-project/issues/97459
2024-09-20[clang][CodeGen] Check initializer of zero-size fields for nullptr (#109271)Michael Buch1-1/+1
In https://github.com/llvm/llvm-project/pull/96422 we started treating empty records as zero-sized for the purpose of layout. In `C`, empty fields were never considered `isZeroSize`, so we would never have tried to call `Init->hasSideEffects` on them. But since https://github.com/llvm/llvm-project/pull/96422 we can get here when compiling `C`, but `Init` need not exist. This patch adds a null-check to account for this situtation.
2024-07-21[PAC] Incorrect codegen for constant global init with polymorphic MI (#99741)Oliver Hunt1-2/+1
Fixes an error where we use the wrong authentication schema for secondary vtable pointers in constant initialized globals of types with multiple polymorphic base classes.
2024-07-16[clang][CGRecordLayout] Remove dependency on isZeroSize (#96422)Michael Buch1-6/+11
This is a follow-up from the conversation starting at https://github.com/llvm/llvm-project/pull/93809#issuecomment-2173729801 The root problem that motivated the change are external AST sources that compute `ASTRecordLayout`s themselves instead of letting Clang compute them from the AST. One such example is LLDB using DWARF to get the definitive offsets and sizes of C++ structures. Such layouts should be considered correct (modulo buggy DWARF), but various assertions and lowering logic around the `CGRecordLayoutBuilder` relies on the AST having `[[no_unique_address]]` attached to them. This is a layout-altering attribute which is not encoded in DWARF. This causes us LLDB to trip over the various LLVM<->Clang layout consistency checks. There has been precedent for avoiding such layout-altering attributes from affecting lowering with externally-provided layouts (e.g., packed structs). This patch proposes to replace the `isZeroSize` checks in `CGRecordLayoutBuilder` (which roughly means "empty field with [[no_unique_address]]") with checks for `CodeGen::isEmptyField`/`CodeGen::isEmptyRecord`. **Details** The main strategy here was to change the `isZeroSize` check in `CGRecordLowering::accumulateFields` and `CGRecordLowering::accumulateBases` to use the `isEmptyXXX` APIs instead, preventing empty fields from being added to the `Members` and `Bases` structures. The rest of the changes fall out from here, to prevent lookups into these structures (for field numbers or base indices) from failing. Added `isEmptyRecordForLayout` and `isEmptyFieldForLayout` (open to better naming suggestions). The main difference to the existing `isEmptyRecord`/`isEmptyField` APIs, is that the `isEmptyXXXForLayout` counterparts don't have special treatment for `unnamed bitfields`/arrays and also treat fields of empty types as if they had `[[no_unique_address]]` (i.e., just like the `AsIfNoUniqueAddr` in `isEmptyField` does).
2024-07-15[clang] Use different memory layout type for _BitInt(N) in LLVM IR (#91364)Mariya Podchishchaeva1-13/+44
There are two problems with _BitInt prior to this patch: 1. For at least some values of N, we cannot use LLVM's iN for the type of struct elements, array elements, allocas, global variables, and so on, because the LLVM layout for that type does not match the high-level layout of _BitInt(N). Example: Currently for i128:128 targets correct implementation is possible either for __int128 or for _BitInt(129+) with lowering to iN, but not both, since we have now correct implementation of __int128 in place after a21abc7. When this happens, opaque [M x i8] types used, where M = sizeof(_BitInt(N)). 2. LLVM doesn't guarantee any particular extension behavior for integer types that aren't a multiple of 8. For this reason, all _BitInt types are now have in-memory representation that is a whole number of bytes. I.e. for example _BitInt(17) now will have memory layout type i32. This patch also introduces concept of load/store type and adds an API to CodeGenTypes that returns the IR type that should be used for load and store operations. This is particularly useful for the case when a _BitInt ends up having array of bytes as memory layout type. For _BitInt(N), let M = sizeof(_BitInt(N)), and let BITS = M * 8. Loads and stores of iM would both (1) produce far better code from the backends and (2) be far more optimizable by IR passes than loads and stores of [M x i8]. Fixes https://github.com/llvm/llvm-project/issues/85139 Fixes https://github.com/llvm/llvm-project/issues/83419 --------- Co-authored-by: John McCall <rjmccall@gmail.com>
2024-07-11[PAC] Implement function pointer type discrimination (#96992)Akira Hatanaka1-9/+23
Give users an option (-fptrauth-function-pointer-type-discrimination) to sign a function pointer using a non-zero discriminator based on the function type. The discriminator is computed by first translating the function type to a string and then computing the hash value of the string. Two function types that are compatible in C must be translated to the same string with the exception of function types that use typedefs of anonymous structs in their return type or parameter types. This patch doesn't have the code to resign function pointers, which is needed when a function pointer is converted to a different function type. That will be implemented in another patch. Co-authored-by: John McCall <rjmccall@apple.com> --------- Co-authored-by: John McCall <rjmccall@apple.com>
2024-06-26 [clang] Implement pointer authentication for C++ virtual functions, ↵Oliver Hunt1-1/+45
v-tables, and VTTs (#94056) Virtual function pointer entries in v-tables are signed with address discrimination in addition to declaration-based discrimination, where an integer discriminator the string hash (see `ptrauth_string_discriminator`) of the mangled name of the overridden method. This notably provides diversity based on the full signature of the overridden method, including the method name and parameter types. This patch introduces ItaniumVTableContext logic to find the original declaration of the overridden method. On AArch64, these pointers are signed using the `IA` key (the process-independent code key.) V-table pointers can be signed with either no discrimination, or a similar scheme using address and decl-based discrimination. In this case, the integer discriminator is the string hash of the mangled v-table identifier of the class that originally introduced the vtable pointer. On AArch64, these pointers are signed using the `DA` key (the process-independent data key.) Not using discrimination allows attackers to simply copy valid v-table pointers from one object to another. However, using a uniform discriminator of 0 does have positive performance and code-size implications on AArch64, and diversity for the most important v-table access pattern (virtual dispatch) is already better assured by the signing schemas used on the virtual functions. It is also known that some code in practice copies objects containing v-tables with `memcpy`, and while this is not permitted formally, it is something that may be invasive to eliminate. This is controlled by: ``` -fptrauth-vtable-pointer-type-discrimination -fptrauth-vtable-pointer-address-discrimination ``` In addition, this provides fine-grained controls in the ptrauth_vtable_pointer attribute, which allows overriding the default ptrauth schema for vtable pointers on a given class hierarchy, e.g.: ``` [[clang::ptrauth_vtable_pointer(no_authentication, no_address_discrimination, no_extra_discrimination)]] [[clang::ptrauth_vtable_pointer(default_key, default_address_discrimination, custom_discrimination, 0xf00d)]] ``` The override is then mangled as a parametrized vendor extension: ``` "__vtptrauth" I <key> <addressDiscriminated> <extraDiscriminator> E ``` To support this attribute, this patch adds a small extension to the attribute-emitter tablegen backend. Note that there are known areas where signing is either missing altogether or can be strengthened. Some will be addressed in later changes (e.g., member function pointers, some RTTI). `dynamic_cast` in particular is handled by emitting an artificial v-table pointer load (in a way that always authenticates it) before the runtime call itself, as the runtime doesn't have enough information today to properly authenticate it. Instead, the runtime is currently expected to strip the v-table pointer. --------- Co-authored-by: John McCall <rjmccall@apple.com> Co-authored-by: Ahmed Bougacha <ahmed@bougacha.org>
2024-06-23[clang][codegen][NFC] Improve const correctnessTimm Bäder1-5/+5
2024-06-21[clang] Implement function pointer signing and authenticated function calls ↵Ahmed Bougacha1-1/+18
(#93906) The functions are currently always signed/authenticated with zero discriminator. Co-Authored-By: John McCall <rjmccall@apple.com>
2024-06-20[clang] Define ptrauth_sign_constant builtin. (#93904)Ahmed Bougacha1-0/+59
This is a constant-expression equivalent to ptrauth_sign_unauthenticated. Its constant nature lets us guarantee a non-attackable sequence is generated, unlike ptrauth_sign_unauthenticated which we generally discourage using. It being a constant also allows its usage in global initializers, though requiring constant pointers and discriminators. The value must be a constant expression of pointer type which evaluates to a non-null pointer. The key must be a constant expression of type ptrauth_key. The extra data must be a constant expression of pointer or integer type; if an integer, it will be coerced to ptrauth_extra_data_t. The result will have the same type as the original value. This can be used in constant expressions. Co-authored-by: John McCall <rjmccall@apple.com>
2024-06-20Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (#95802)Mariya Podchishchaeva1-25/+93
This commit implements the entirety of the now-accepted [N3017 -Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. This reverts commit https://github.com/llvm/llvm-project/commit/682d461d5a231cee54d65910e6341769419a67d7. --------- Co-authored-by: The Phantom Derpstorm <phdofthehouse@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
2024-06-12Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C ↵Vitaly Buka1-93/+25
and Obj-C++ by-proxy)" (#95299) Reverts llvm/llvm-project#68620 Introduce or expose a memory leak and UB, see llvm/llvm-project#68620
2024-06-12[clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and ↵The Phantom Derpstorm1-25/+93
Obj-C++ by-proxy) (#68620) This commit implements the entirety of the now-accepted [N3017 - Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com> Co-authored-by: Podchishchaeva, Mariya <mariya.podchishchaeva@intel.com>
2024-06-11[clang] Replace X && isa<Y>(X) with isa_and_nonnull<Y>(X). NFC (#94987)Pavel Samolysov1-1/+1
This addresses a clang-tidy suggestion.
2024-05-17[CodeGen] Support arrays with initializers of 64-bit sizeFangrui Song1-7/+7
Based on @OfekShochat's https://reviews.llvm.org/D133648 init.c is the primary test for array initialization, but it uses a 32-bit triple, which would lead to an "array is too large" error. Add the new test to array-init.c instead. Fix #57353 Pull Request: https://github.com/llvm/llvm-project/pull/92473
2024-04-23[clang][CodeGen][NFC] Make ConstExprEmitter a ConstStmtVisitor (#89041)Timm Baeder1-52/+56
No reason for this to not be one. This gets rid of a few const_casts.
2024-04-18[clang][NFC] Fix FieldDecl::isUnnamedBitfield() capitalization (#89048)Timm Baeder1-2/+2
We always capitalize bitfield as "BitField".
2024-04-01[HLSL] Implement array temporary support (#79382)Chris B1-0/+1
HLSL constant sized array function parameters do not decay to pointers. Instead constant sized array types are preserved as unique types for overload resolution, template instantiation and name mangling. This implements the change by adding a new `ArrayParameterType` which represents a non-decaying `ConstantArrayType`. The new type behaves the same as `ConstantArrayType` except that it does not decay to a pointer. Values of `ConstantArrayType` in HLSL decay during overload resolution via a new `HLSLArrayRValue` cast to `ArrayParameterType`. `ArrayParamterType` values are passed indirectly by-value to functions in IR generation resulting in callee generated memcpy instructions. The behavior of HLSL function calls is documented in the [draft language specification](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf) under the Expr.Post.Call heading. Additionally the design of this implementation approach is documented in [Clang's documentation](https://clang.llvm.org/docs/HLSL/FunctionCalls.html) Resolves #70123
2024-03-28[CodeGen][arm64e] Add methods and data members to Address, which are needed ↵Akira Hatanaka1-2/+2
to authenticate signed pointers (#86923) To authenticate pointers, CodeGen needs access to the key and discriminators that were used to sign the pointer. That information is sometimes known from the context, but not always, which is why `Address` needs to hold that information. This patch adds methods and data members to `Address`, which will be needed in subsequent patches to authenticate signed pointers, and uses the newly added methods throughout CodeGen. Although this patch isn't strictly NFC as it causes CodeGen to use different code paths in some cases (e.g., `mergeAddressesInConditionalExpr`), it doesn't cause any changes in functionality as it doesn't add any information needed for authentication. In addition to the changes mentioned above, this patch introduces class `RawAddress`, which contains a pointer that we know is unsigned, and adds several new functions for creating `Address` and `LValue` objects. This reapplies d9a685a9dd589486e882b722e513ee7b8c84870c, which was reverted because it broke ubsan bots. There seems to be a bug in coroutine code-gen, which is causing EmitTypeCheck to use the wrong alignment. For now, pass alignment zero to EmitTypeCheck so that it can compute the correct alignment based on the passed type (see function EmitCXXMemberOrOperatorMemberCallExpr).
2024-03-27Revert "[CodeGen][arm64e] Add methods and data members to Address, which are ↵Akira Hatanaka1-2/+2
needed to authenticate signed pointers (#86721)" (#86898) This reverts commit d9a685a9dd589486e882b722e513ee7b8c84870c. The commit broke ubsan bots.
2024-03-27[CodeGen][arm64e] Add methods and data members to Address, which are needed ↵Akira Hatanaka1-2/+2
to authenticate signed pointers (#86721) To authenticate pointers, CodeGen needs access to the key and discriminators that were used to sign the pointer. That information is sometimes known from the context, but not always, which is why `Address` needs to hold that information. This patch adds methods and data members to `Address`, which will be needed in subsequent patches to authenticate signed pointers, and uses the newly added methods throughout CodeGen. Although this patch isn't strictly NFC as it causes CodeGen to use different code paths in some cases (e.g., `mergeAddressesInConditionalExpr`), it doesn't cause any changes in functionality as it doesn't add any information needed for authentication. In addition to the changes mentioned above, this patch introduces class `RawAddress`, which contains a pointer that we know is unsigned, and adds several new functions for creating `Address` and `LValue` objects. This reapplies 8bd1f9116aab879183f34707e6d21c7051d083b6. The commit broke msan bots because LValue::IsKnownNonNull was uninitialized.
2024-03-26[NFC] Refactor ConstantArrayType size storage (#85716)Chris B1-4/+4
In PR #79382, I need to add a new type that derives from ConstantArrayType. This means that ConstantArrayType can no longer use `llvm::TrailingObjects` to store the trailing optional Expr*. This change refactors ConstantArrayType to store a 60-bit integer and 4-bits for the integer size in bytes. This replaces the APInt field previously in the type but preserves enough information to recreate it where needed. To reduce the number of places where the APInt is re-constructed I've also added some helper methods to the ConstantArrayType to allow some common use cases that operate on either the stored small integer or the APInt as appropriate. Resolves #85124.
2024-03-26Revert "[CodeGen][arm64e] Add methods and data members to Address, which are ↵Akira Hatanaka1-2/+2
needed to authenticate signed pointers (#67454)" (#86674) This reverts commit 8bd1f9116aab879183f34707e6d21c7051d083b6. It appears that the commit broke msan bots.
2024-03-25[CodeGen][arm64e] Add methods and data members to Address, which are needed ↵Akira Hatanaka1-2/+2
to authenticate signed pointers (#67454) To authenticate pointers, CodeGen needs access to the key and discriminators that were used to sign the pointer. That information is sometimes known from the context, but not always, which is why `Address` needs to hold that information. This patch adds methods and data members to `Address`, which will be needed in subsequent patches to authenticate signed pointers, and uses the newly added methods throughout CodeGen. Although this patch isn't strictly NFC as it causes CodeGen to use different code paths in some cases (e.g., `mergeAddressesInConditionalExpr`), it doesn't cause any changes in functionality as it doesn't add any information needed for authentication. In addition to the changes mentioned above, this patch introduces class `RawAddress`, which contains a pointer that we know is unsigned, and adds several new functions for creating `Address` and `LValue` objects.
2024-02-15[HLSL] Vector standard conversions (#71098)Chris B1-0/+1
HLSL supports vector truncation and element conversions as part of standard conversion sequences. The vector truncation conversion is a C++ second conversion in the conversion sequence. If a vector truncation is in a conversion sequence an element conversion may occur after it before the standard C++ third conversion. Vector element conversions can be boolean conversions, floating point or integral conversions or promotions. [HLSL Draft Specification](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf) --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-01-30[clang][NFC] Use no-param version of skipRValueSubobjectAdjustmentsTimm Bäder1-4/+1
when possible.
2024-01-27[Clang][C++26] Implement Pack Indexing (P2662R3). (#72644)cor3ntin1-0/+4
Implements https://isocpp.org/files/papers/P2662R3.pdf The feature is exposed as an extension in older language modes. Mangling is not yet supported and that is something we will have to do before release.
2023-11-23[clang][CGExprConstant] Remove no-op ptr-to-ptr bitcast (NFC)Youngsuk Kim1-4/+1
Remove a call to `getPointerCast` which is effectively does a no-op ptr-to-ptr bitcast. Opaque ptr clean-up effort.
2023-11-02[clang] Remove no-op ptr-to-ptr bitcasts (NFC)Youngsuk Kim1-9/+2
Opaque ptr cleanup effort (NFC)
2023-11-01[CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC)Nikita Popov1-2/+3
We're working on a ConstantInt here, so folding cannot fail. Only avoid the API use.
2023-10-30[clang] Implement constexpr bit_cast for vectors (#66894)DaPorkchop_1-0/+3
This makes __builtin_bit_cast support converting to and from vector types in a constexpr context.
2023-10-30[CGExprConstant] stop calling into ConstExprEmitter for Reference type ↵Nick Desaulniers1-3/+4
destinations (#70366) Fixes a bug introduced by commit b54294e2c959 ("[clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first") In the added test case, the QualType is a LValueReferenceType. LValueReferenceType 0x558412998d90 'const char (&)[41]' `-ParenType 0x558412998d30 'const char[41]' sugar `-ConstantArrayType 0x558412998cf0 'const char[41]' 41 `-QualType 0x55841294c271 'const char' const `-BuiltinType 0x55841294c270 'char' Fixes: #69979