llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> So we can pass them on do `diagnoseNonConstVariable`. This doesn't make a difference right now but is needed for a future commit. --- Full diff: https://github.com/llvm/llvm-project/pull/205720.diff 3 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+11-9) - (modified) clang/lib/AST/ByteCode/Interp.h (+2-1) - (modified) clang/lib/AST/ByteCode/InterpHelpers.h (+5-3) ``````````diff 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. `````````` </details> https://github.com/llvm/llvm-project/pull/205720 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
