[clang] [clang] Add support for relaxed constexpr evaluation to interpreter (PR #217311)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 19 05:22:14 PDT 2026
================
@@ -2713,9 +2715,13 @@ bool InvalidShuffleVectorIndex(InterpState &S, CodePtr OpPC, uint32_t Index) {
bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC,
const Pointer &Ptr, unsigned BitWidth) {
SourceInfo E = S.Current->getSource(OpPC);
- S.CCEDiag(E, diag::note_constexpr_invalid_cast)
- << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
+ S.CCEDiag(E, diag::note_constexpr_invalid_cast_ptrtoint)
+ << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
+ << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
+ APValue V = Ptr.toAPValue(S.getASTContext());
+ if (V.getLValueBase())
+ S.CCEDiag(E, diag::note_constexpr_has_lvalue) << S.Current->getRange(OpPC);
----------------
eleviant wrote:
Here we check that the base of LValue is not null. In this sense the declaration below won't pass the check:
```
struct Foo object;
constexpr uintptr_t v = (uintptr_t)&object
```
and this one will:
```
constexpr uintptr_t offtset = (uintptr)&(((Foo*)nullptr)->field);
```
I don't think `Ptr.isZero()` would work, because in both cases pointer is not zero.
https://github.com/llvm/llvm-project/pull/217311
More information about the cfe-commits
mailing list