Skip to content

Commit 9876343

Browse files
authored
[clang][bytecode] Optimize enum value range checks (#139672)
Only do the work if we really have to.
1 parent 6d35ec2 commit 9876343

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,12 +1251,11 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
12511251

12521252
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,
12531253
const APSInt &Value) {
1254-
llvm::APInt Min;
1255-
llvm::APInt Max;
1256-
12571254
if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr())
12581255
return;
12591256

1257+
llvm::APInt Min;
1258+
llvm::APInt Max;
12601259
ED->getValueRange(Max, Min);
12611260
--Max;
12621261

clang/lib/AST/ByteCode/Interp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,10 +3026,11 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
30263026
inline bool CheckEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED) {
30273027
assert(ED);
30283028
assert(!ED->isFixed());
3029-
const APSInt Val = S.Stk.peek<T>().toAPSInt();
30303029

3031-
if (S.inConstantContext())
3030+
if (S.inConstantContext()) {
3031+
const APSInt Val = S.Stk.peek<T>().toAPSInt();
30323032
diagnoseEnumValue(S, OpPC, ED, Val);
3033+
}
30333034
return true;
30343035
}
30353036

0 commit comments

Comments
 (0)