Author: Timm Baeder Date: 2026-10-01T15:27:47+02:00 New Revision: 8d63a4d4cc75f018a7e376ba1247f9e343438600
URL: https://github.com/llvm/llvm-project/commit/8d63a4d4cc75f018a7e376ba1247f9e343438600 DIFF: https://github.com/llvm/llvm-project/commit/8d63a4d4cc75f018a7e376ba1247f9e343438600.diff LOG: [clang][bytecode][NFC] Don't take a pointer in CheckArraySize (#227976) We used to assign a new value to NumElements, but we don't anymore. Added: Modified: clang/lib/AST/ByteCode/Interp.h clang/lib/AST/ByteCode/InterpHelpers.h Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index aed1e17a97479..7592d9e3c68ea 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -3979,7 +3979,7 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source, return false; SizeT NumElements = S.Stk.pop<SizeT>(); - if (!CheckArraySize(S, OpPC, &NumElements, primSize(T), IsNoThrow)) { + if (!CheckArraySize(S, OpPC, NumElements, primSize(T), IsNoThrow)) { if (!IsNoThrow) return false; @@ -4021,7 +4021,7 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc, return false; SizeT NumElements = S.Stk.pop<SizeT>(); - if (!CheckArraySize(S, OpPC, &NumElements, ElementDesc->getSize(), + if (!CheckArraySize(S, OpPC, NumElements, ElementDesc->getSize(), IsNoThrow)) { if (!IsNoThrow) return false; diff --git a/clang/lib/AST/ByteCode/InterpHelpers.h b/clang/lib/AST/ByteCode/InterpHelpers.h index f9dba752d9749..a6c6afeacecb3 100644 --- a/clang/lib/AST/ByteCode/InterpHelpers.h +++ b/clang/lib/AST/ByteCode/InterpHelpers.h @@ -143,7 +143,7 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) { } template <typename SizeT> -bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements, +bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT NumElements, unsigned ElemSize, bool IsNoThrow) { if (ElemSize == 0) @@ -154,7 +154,7 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements, // Can't be too many elements if the bitwidth of NumElements is lower than // that of Descriptor::MaxArrayElemBytes. - if ((NumElements->bitWidth() - NumElements->isSigned()) < + if ((NumElements.bitWidth() - NumElements.isSigned()) < (sizeof(Descriptor::MaxArrayElemBytes) * 8)) return true; @@ -164,18 +164,16 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements, // constructing the array, we catch this here. SizeT MaxElements = SizeT::from(Descriptor::MaxArrayElemBytes / ElemSize); assert(MaxElements.isPositive()); - if (NumElements->toAPSInt().getActiveBits() > + if (NumElements.toAPSInt().getActiveBits() > ConstantArrayType::getMaxSizeBits(S.getASTContext()) || - *NumElements > MaxElements) { + NumElements > MaxElements) { if (!IsNoThrow) { - const SourceInfo &Loc = S.Current->getSource(OpPC); - - if (NumElements->isSigned() && NumElements->isNegative()) { - S.FFDiag(Loc, diag::note_constexpr_new_negative) - << NumElements->toDiagnosticString(S.getASTContext()); + if (NumElements.isSigned() && NumElements.isNegative()) { + S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_new_negative) + << NumElements.toDiagnosticString(S.getASTContext()); } else { - S.FFDiag(Loc, diag::note_constexpr_new_too_large) - << NumElements->toDiagnosticString(S.getASTContext()); + S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_new_too_large) + << NumElements.toDiagnosticString(S.getASTContext()); } } return false; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
