[clang] a6e3bf8 - [clang][bytecode] Pass AccessKinds to Check{Constant,Mutable} (#205720)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 23:06:35 PDT 2026
Author: Timm Baeder
Date: 2026-06-25T08:06:31+02:00
New Revision: a6e3bf89bf3d55136a6b10d7269eead564f6b96f
URL: https://github.com/llvm/llvm-project/commit/a6e3bf89bf3d55136a6b10d7269eead564f6b96f
DIFF: https://github.com/llvm/llvm-project/commit/a6e3bf89bf3d55136a6b10d7269eead564f6b96f.diff
LOG: [clang][bytecode] Pass AccessKinds to Check{Constant,Mutable} (#205720)
So we can pass them on do `diagnoseNonConstVariable`.
This doesn't make a difference right now but is needed for a future
commit.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/InterpHelpers.h
Removed:
################################################################################
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