aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-03-21Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (#132317)Matheus Izvekov1-2/+3
Relands Original PR: https://github.com/llvm/llvm-project/pull/131965 Addresses https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498 * Fixes isIncompleteType for injected classes This clears up some uses of getClass on MemberPointerType when equivalent uses of getMostRecentCXXRecordDecl would be just as simple or simpler. This is split-off from a larger patch which removes getClass, in order to facilitate review.
2025-03-21[clang][ExprConst] Check record base classes for valid structs (#132270)Timm Baeder1-1/+6
In error cases, the base might be None. Fixes https://github.com/llvm/llvm-project/issues/132257
2025-03-20Revert "[clang] NFC: Clear some uses of MemberPointerType::getClass" (#132281)Matheus Izvekov1-3/+2
Reverts llvm/llvm-project#131965 Reverted due to issue reported here: https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-19[clang] NFC: Clear some uses of MemberPointerType::getClass (#131965)Matheus Izvekov1-2/+3
2025-03-19[clang][diagnostics] Update note_constexpr_invalid_cast to use enum_select ↵Ayokunle Amodu1-8/+16
and adjust its uses (#130868) Handles #123121 This patch updates `note_constexpr_invalid_cast` diagnostic to use `enum_select` instead of `select,` improving readability and reducing reliance on magic numbers in caller sites.
2025-03-18[Clang] Introduce a trait to determine the structure binding size (#131515)cor3ntin1-1/+6
Introduce a trait to determine the number of bindings that would be produced by ```cpp auto [...p] = expr; ``` This is necessary to implement P2300 (https://eel.is/c++draft/exec#snd.concepts-5), but can also be used to implement a general get<N> function that supports aggregates `__builtin_structured_binding_size` is a unary type trait that evaluates to the number of bindings in a decomposition If the argument cannot be decomposed, a sfinae-friendly error is produced. A type is considered a valid tuple if `std::tuple_size_v<T>` is a valid expression, even if there is no valid `std::tuple_element` specialization or suitable `get` function for that type. Fixes #46049
2025-03-17[Clang] Constant Expressions inside of GCC' asm strings (#131003)cor3ntin1-11/+40
Implements GCC's constexpr string ASM extension https://gcc.gnu.org/onlinedocs/gcc/Asm-constexprs.html
2025-03-11[HLSL] Make memory representation of boolean vectors in HLSL, vectors of ↵Sarah Spall1-4/+5
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-11[Clang] Implement P0963R3 "Structured binding declaration as a condition" ↵Younan Zhang1-7/+34
(#130228) This implements the R2 semantics of P0963. The R1 semantics, as outlined in the paper, were introduced in Clang 6. In addition to that, the paper proposes swapping the evaluation order of condition expressions and the initialization of binding declarations (i.e. std::tuple-like decompositions).
2025-03-10[clang][NFC] Clean up Expr::EvaluateAsConstantExpr (#130498)Timm Baeder1-17/+12
The Info.EnableNewConstInterp case is already handled above.
2025-03-09[clang] Reject constexpr-unknown values as constant expressions more ↵Eli Friedman1-13/+12
consistently (#129952) Perform the check for constexpr-unknown values in the same place we perform checks for other values which don't count as constant expressions. While I'm here, also fix a rejects-valid with a reference that doesn't have an initializer. This diagnostic was also covering up some of the bugs here. The existing behavior with -fexperimental-new-constant-interpreter seems to be correct, but the diagnostics are slightly different; it would be helpful if someone could check on that as a followup. Followup to #128409. Fixes #129844. Fixes #129845.
2025-03-05[Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` ↵Yingwei Zheng1-2/+12
(#128409) It is an alternative to https://github.com/llvm/llvm-project/pull/127525. Close https://github.com/llvm/llvm-project/issues/127475.
2025-03-04Clang: ExprConstant use maxnum/minnum for fmax/fmin (#129630)YunQiang Su1-12/+2
In APFloat, we have defined maxnum and minnum, so let's use them directly here. In `maxnum`/`minnum` of APFloat, we process sNaN, signed-zero as strictly as possible.
2025-02-27[Clang][Sema] Add special handling of mfloat8 in initializer lists (#125097)Lukacma1-0/+5
This patch fixes assertion failures in clang, caused by unique properties of _mfp8 type, namely it not being either scalar or vector type and it not being either integer or float type.
2025-02-18[Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into ↵Jason Rice1-1/+0
FunctionParmPackExpr (#125394) This merges the functionality of ResolvedUnexpandedPackExpr into FunctionParmPackExpr. I also added a test to show that https://github.com/llvm/llvm-project/issues/125103 should be fixed with this. I put the removal of ResolvedUnexpandedPackExpr in its own commit. Let me know what you think. Fixes #125103
2025-02-14[HLSL] Implement HLSL Aggregate splatting (#118992)Sarah Spall1-0/+2
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-11[NFC] [clang] simplify isDesignatorAtObjectEnd (#126658)Florian Mayer1-12/+8
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
2025-02-07[HLSL] Implement HLSL Elementwise casting (excluding splat cases); Re-land ↵Sarah Spall1-0/+2
#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-2/+0
Reverts llvm/llvm-project#118842
2025-02-06[HLSL] Implement HLSL Flat casting (excluding splat cases) (#118842)Sarah Spall1-0/+2
Implement HLSLElementwiseCast excluding support for splat cases Do not support casting types that contain bitfields. Partly closes #100609 and partly closes #100619
2025-01-29[Clang][P1061] Add stuctured binding packs (#121417)Jason Rice1-1/+2
This is an implementation of P1061 Structure Bindings Introduce a Pack without the ability to use packs outside of templates. There is a couple of ways the AST could have been sliced so let me know what you think. The only part of this change that I am unsure of is the serialization/deserialization stuff. I followed the implementation of other Exprs, but I do not really know how it is tested. Thank you for your time considering this. --------- Co-authored-by: Yanzuo Liu <zwuis@outlook.com>
2025-01-28[clang][ExprConst] Don't diagnose a non-existent init as not constant (#124575)Timm Baeder1-2/+6
This test: ```c++ extern Swim& trident; // expected-note {{declared here}} constexpr auto& gallagher = typeid(trident); // expected-error {{constexpr variable 'gallagher' must be initialized by a constant expression}} // expected-note@-1 {{initializer of 'trident' is not a constant expression}} ``` diagnosed the initializer of `trident` as not constant, but `trident` doesn't even have an initializer. Remove that diagnostic in this case.
2025-01-26[Clang] Fix createConstexprUnknownAPValues to use zero offset when ceating ↵Shafik Yaghmour1-1/+1
APValue (#124478) When implmenting P2280R4 here: https://github.com/llvm/llvm-project/pull/95474 When creating the APValue to store and constexprUnknown value I used an offset of CharUnits::One() but it should have been CharUnits::Zero(). This change just adjusts that value.
2025-01-24[clang][ExprConst] Let diagnostics point to std::allocator calls (#123744)Timm Baeder1-2/+3
Instead of the underlying operator new calls. This fixes a longstanding FIXME comment in cxx2a-constexpr-dynalloc.cpp.
2025-01-22[Clang] Implement P2280R4 Using unknown pointers and references in constant ↵Shafik Yaghmour1-9/+123
expressions (#95474) P2280R4 allows the use of references in pointers of unknown origins in a constant expression context but only in specific cases that could be constant expressions. We track whether a variable is a constexpr unknown in a constant expression by setting a flag in either APValue or LValue and using this flag to prevent using unknown values in places where it is not allowed. Fixes: https://github.com/llvm/llvm-project/issues/63139 https://github.com/llvm/llvm-project/issues/63117
2025-01-11Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289)Timm Baeder1-1/+1
2025-01-09[clang][ExprConst] Add diagnostics for invalid binary arithmetic (#118475)Timm Baeder1-1/+17
... between unrelated declarations or literals. Leaving this small (I haven't run the whole test suite locally) to get some feedback on the wording and implementation first. The output of the sample in https://github.com/llvm/llvm-project/issues/117409 is now: ```console ./array.cpp:57:6: warning: expression result unused [-Wunused-value] 57 | am - aj.af(); | ~~ ^ ~~~~~~~ ./array.cpp:70:8: error: call to consteval function 'L::L<bx>' is not a constant expression 70 | q(0, [] { | ^ ./array.cpp:57:6: note: arithmetic on addresses of literals has unspecified value 57 | am - aj.af(); | ^ ./array.cpp:62:5: note: in call to 'al(&""[0], {&""[0]})' 62 | al(bp.af(), k); | ^~~~~~~~~~~~~~ ./array.cpp:70:8: note: in call to 'L<bx>({})' 70 | q(0, [] { | ^~~~ 71 | struct bx { | ~~~~~~~~~~~ 72 | constexpr operator ab<g<l<decltype(""[0])>::e>::e>() { return t(""); } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | }; | ~~ 74 | return bx(); | ~~~~~~~~~~~~ 75 | }()); | ~~~ ``` The output for ```c++ int a, b; constexpr int n = &b - &a ``` is now: ```console ./array.cpp:80:15: error: constexpr variable 'n' must be initialized by a constant expression 80 | constexpr int n = &b - &a; | ^ ~~~~~~~ ./array.cpp:80:22: note: arithmetic involving '&b' and '&a' has unspecified value 80 | constexpr int n = &b - &a; | ^ 1 error generated. ```
2025-01-08Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"Timm Bäder1-1/+1
This reverts commit 81fc3add1e627c23b7270fe2739cdacc09063e54. This breaks some LLDB tests, e.g. SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp: lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
2025-01-08[clang] Avoid re-evaluating field bitwidth (#117732)Timm Baeder1-1/+1
Save the bitwidth value as a `ConstantExpr` with the value set. Remove the `ASTContext` parameter from `getBitWidthValue()`, so the latter simply returns the value from the `ConstantExpr` instead of constant-evaluating the bitwidth expression every time it is called.
2025-01-03Factor common code for quoting a builtin name (#120835)Chandler Carruth1-8/+7
This shows up in several places in order to match the quoting of other uses of the same diagnostic. Handling it centrally simplifies the code and reduces changes if the storage for builtin names changes. This refactoring is extracted out of #120534 as requested in code review.
2024-12-23[clang] constexpr built-in reduce min/max function. (#120866)c8ef1-1/+11
Part of #51787. This patch adds constexpr support for the built-in reduce min/max function.
2024-12-10[clang][ExprConst] Move vector diagnostics to checkBitCastConstexprEl… ↵Timm Baeder1-47/+26
(#119366) …igibilityType This is the function we use to diagnose invalid types, so use it for those checks as well. NFC.
2024-12-10[ExprConst] Handle floating- and char literals in FastEvaluateAsRValue (#118294)Timm Baeder1-1/+13
This is part of a three-patch series that results in some nice (but not substantial) compile-time improvements: http://llvm-compile-time-tracker.com/compare.php?from=fe1c4f0106fe4fd6d61c38ba46e71fda8f4d1573&to=0824d621b2c035a3befb564153b31309a9a79d97&stat=instructions%3Au The results for just this patch are here: http://llvm-compile-time-tracker.com/compare.php?from=fe1c4f0106fe4fd6d61c38ba46e71fda8f4d1573&to=6f7f51b476a37dc7c80427fede077e6798a83be8&stat=instructions:u
2024-12-09[Clang] allow usage of placement new operator in [[msvc::constexpr]] context ↵Oleksandr T.1-1/+3
outside of the std namespace (#119153) Fixes #74924
2024-12-09[clang] constexpr built-in elementwise add_sat/sub_sat functions. (#119082)c8ef1-0/+50
Part of #51787. This patch adds constexpr support for the built-in elementwise add_sat and sub_sat functions.
2024-12-03[clang] constexpr built-in elementwise bitreverse function. (#118177)c8ef1-5/+16
Part of #51787. This patch adds constexpr support for the built-in elementwise bitreverse function.
2024-11-26[clang] constexpr built-in elementwise popcount function. (#117473)c8ef1-0/+31
Part of #51787. This patch adds constexpr support for the built-in elementwise popcount function.
2024-11-25[clang][NFC]add static for internal linkage function (#117482)Congcong Cai1-3/+3
Detected by misc-use-internal-linkage
2024-11-21[clang][ExprConst] Reject field access with nullptr base (#113885)Timm Baeder1-3/+3
Reject them if the base is null, not only if the entire pointer is null. Fixes #113821
2024-11-21[clang] constexpr built-in reduce `or` and `xor` function. (#116976)c8ef1-1/+11
Part of #51787. Follow up of #116822. This patch adds constexpr support for the built-in reduce `or` and `xor` functions.
2024-11-20[clang] constexpr built-in reduce and function. (#116822)c8ef1-1/+6
Part of #51787. Follow up of #116626. This patch adds constexpr support for the built-in reduce and function.
2024-11-19[clang] constexpr built-in reduce mul function. (#116626)c8ef1-4/+19
Part of #51787. Follow up of #116243. This patch adds constexpr support for the built-in reduce mul function.
2024-11-18[clang] constexpr built-in reduce add function. (#116243)c8ef1-0/+17
Part of #51787. This patch adds constexpr support for the built-in reduce add function. If this is the right way to go, I will add support for other reduce functions in later patches. --------- Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
2024-11-17[AST] Remove unused includes (NFC) (#116549)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-24[Clang] prevent assertion failure in value-dependent initializer expressions ↵Oleksandr T.1-0/+3
(#112612) Fixes #112140 --- ``` CXXConstructExpr 0x14209e580 'const S':'const struct S' contains-errors 'void (const int &)' list `-CXXDefaultArgExpr 0x14209e500 'const int' contains-errors `-RecoveryExpr 0x14209daf0 'const int' contains-errors ``` This change resolves an issue with evaluating `ArrayFiller` initializers in _dependent_ contexts, especially when they involve a `RecoveryExpr`. In certain cases, `ArrayFiller` initializers containing a `RecoveryExpr` from earlier errors are incorrectly passed to `EvaluateInPlace`, causing evaluation failures when they are value-dependent. When this is the case, the initializer is processed through `EvaluateDependentExpr`, which prevents unnecessary evaluation attempts and ensures proper handling of value-dependent initializers in `ArrayFillers`.
2024-10-18[clang] constexpr built-in abs function. (#112539)c8ef1-0/+14
According to [P0533R9](https://wg21.link/P0533R9), the C++ standard library functions corresponding to the C macros in `[c.math.abs]` are now `constexpr`. To implement this feature in libc++, we must make the built-in abs function `constexpr`. This patch adds the implementation of a `constexpr` abs function for the current constant evaluator and the new bytecode interpreter. It is important to note that in 2's complement systems, the absolute value of the most negative value is out of range. In gcc, it will result in an out-of-range error and will not be evaluated as constants. We follow the same approach here.
2024-10-16[clang] Implement constexpr __builtin_bit_cast for complex types (#109981)Timm Baeder1-0/+43
Fixes https://github.com/llvm/llvm-project/issues/94620
2024-10-15[HLSL] Make HLSLAttributedResourceType canonical and add code paths to ↵Helena Kotas1-0/+1
convert HLSL types to DirectX target types (#110327) Translates `RWBuffer` and `StructuredBuffer` resources buffer types to DirectX target types `dx.TypedBuffer` and `dx.RawBuffer`. Includes a change of `HLSLAttributesResourceType` from 'sugar' type to full canonical type. This is required for codegen and other clang infrastructure to work property on HLSL resource types. Fixes #95952 (part 2/2)
2024-10-14Clang: Support minimumnum and maximumnum intrinsics (#96281)YunQiang Su1-0/+26
We just introduce llvm.minimumnum and llvm.maximumnum intrinsics support to llvm. Let's support them in Clang. See: #93033
2024-10-11[clang][bytecode] Implement __builtin_assume_aligned (#111968)Timm Baeder1-18/+17