From 98763433e66dd91bf5f10b1daf03d9373f07912a Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Tue, 13 May 2025 10:55:24 +0200 Subject: [PATCH] [clang][bytecode] Optimize enum value range checks (#139672) Only do the work if we really have to. --- clang/lib/AST/ByteCode/Interp.cpp | 5 ++--- clang/lib/AST/ByteCode/Interp.h | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 43f8d156589b..91930c016c98 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -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; diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index a13fd6c1f1da..35d97167135f 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -3026,10 +3026,11 @@ template ::T> inline bool CheckEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED) { assert(ED); assert(!ED->isFixed()); - const APSInt Val = S.Stk.peek().toAPSInt(); - if (S.inConstantContext()) + if (S.inConstantContext()) { + const APSInt Val = S.Stk.peek().toAPSInt(); diagnoseEnumValue(S, OpPC, ED, Val); + } return true; }