[clang][bytecode] Optimize enum value range checks (#139672)

Only do the work if we really have to.
This commit is contained in:
Timm Baeder 2025-05-13 10:55:24 +02:00 committed by GitHub
parent 6d35ec2335
commit 98763433e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -1251,12 +1251,11 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,
const APSInt &Value) {
llvm::APInt Min;
llvm::APInt Max;
if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr())
return;
llvm::APInt Min;
llvm::APInt Max;
ED->getValueRange(Max, Min);
--Max;

View File

@ -3026,10 +3026,11 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
inline bool CheckEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED) {
assert(ED);
assert(!ED->isFixed());
const APSInt Val = S.Stk.peek<T>().toAPSInt();
if (S.inConstantContext())
if (S.inConstantContext()) {
const APSInt Val = S.Stk.peek<T>().toAPSInt();
diagnoseEnumValue(S, OpPC, ED, Val);
}
return true;
}