[clang] [clang][bytecode] Pass AccessKinds to Check{Constant, Mutable} (PR #205720)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 21:58:20 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/205720
So we can pass them on do `diagnoseNonConstVariable`.
This doesn't make a difference right now but is needed for a future commit.
>From 73a82704fbadfa33b586c502953e2d4593c33e66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 25 Jun 2026 06:30:03 +0200
Subject: [PATCH] AK
---
clang/lib/AST/ByteCode/Interp.cpp | 20 +++++++++++---------
clang/lib/AST/ByteCode/Interp.h | 3 ++-
clang/lib/AST/ByteCode/InterpHelpers.h | 8 +++++---
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 3772def47408f..3d5fda7ddf3c7 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -454,7 +454,8 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return true;
}
-bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
+bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc,
+ AccessKinds AK) {
assert(Desc);
const auto *D = Desc->asVarDecl();
@@ -472,7 +473,7 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
bool IsConstant = T.isConstant(S.getASTContext());
if (T->isIntegralOrEnumerationType()) {
if (!IsConstant) {
- diagnoseNonConstVariable(S, OpPC, D);
+ diagnoseNonConstVariable(S, OpPC, D, AK);
return false;
}
return true;
@@ -496,22 +497,23 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
if (T->isPointerOrReferenceType()) {
if (!T->getPointeeType().isConstant(S.getASTContext()) ||
!S.getLangOpts().CPlusPlus11) {
- diagnoseNonConstVariable(S, OpPC, D);
+ diagnoseNonConstVariable(S, OpPC, D, AK);
return false;
}
return true;
}
- diagnoseNonConstVariable(S, OpPC, D);
+ diagnoseNonConstVariable(S, OpPC, D, AK);
return false;
}
-static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+static bool CheckConstant(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+ AccessKinds AK = AK_Read) {
if (!Ptr.isStatic() || !Ptr.isBlockPointer())
return true;
if (!Ptr.getDeclID())
return true;
- return CheckConstant(S, OpPC, Ptr.getDeclDesc());
+ return CheckConstant(S, OpPC, Ptr.getDeclDesc(), AK);
}
bool CheckNull(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
@@ -641,7 +643,7 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
return false;
}
-bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr) {
+bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr, AccessKinds AK) {
assert(Ptr.isLive() && "Pointer is not live");
if (!Ptr.isMutable())
return true;
@@ -653,7 +655,7 @@ bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
const FieldDecl *Field = Ptr.getField();
- S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK_Read << Field;
+ S.FFDiag(Loc, diag::note_constexpr_access_mutable, 1) << AK << Field;
S.Note(Field->getLocation(), diag::note_declared_at);
return false;
}
@@ -874,7 +876,7 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return CheckWeak(S, OpPC, Ptr.block());
}
- if (!CheckConstant(S, OpPC, Ptr))
+ if (!CheckConstant(S, OpPC, Ptr, AK))
return false;
if (!CheckRange(S, OpPC, Ptr, AK))
return false;
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index d1836b6b739b2..ed640f7325f7e 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -75,7 +75,8 @@ bool CheckDowncast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
/// Checks if the Descriptor is of a constexpr or const global variable.
-bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc);
+bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc,
+ AccessKinds AK = AK_Read);
bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
diff --git a/clang/lib/AST/ByteCode/InterpHelpers.h b/clang/lib/AST/ByteCode/InterpHelpers.h
index 5c6ba0eda5de3..da305dcb565d5 100644
--- a/clang/lib/AST/ByteCode/InterpHelpers.h
+++ b/clang/lib/AST/ByteCode/InterpHelpers.h
@@ -58,11 +58,13 @@ bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
CheckSubobjectKind CSK);
/// Checks if a pointer points to a mutable field.
-bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr);
-inline bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+bool CheckMutable(InterpState &S, CodePtr OpPC, PtrView Ptr,
+ AccessKinds AK = AK_Read);
+inline bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+ AccessKinds AK = AK_Read) {
if (!Ptr.isBlockPointer())
return true;
- return CheckMutable(S, OpPC, Ptr.view());
+ return CheckMutable(S, OpPC, Ptr.view(), AK);
}
/// Checks if a value can be loaded from a block.
More information about the cfe-commits
mailing list