https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/156019
This should allow us to reuse these cases for the shift-by-immediate builtins in #155542 >From a039f7803c00069517084455491d18f53659e0c2 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim <[email protected]> Date: Fri, 29 Aug 2025 14:00:12 +0100 Subject: [PATCH] [clang][x86] Ensure we use the shifted value bit width to check for out of bounds per-element shift amounts This should allow us to reuse these cases for the shift-by-immediate builtins in #155542 --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index eba0b25997699..3bfe54e00a049 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -3256,8 +3256,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, case clang::X86::BI__builtin_ia32_psllv8si: return interp__builtin_elementwise_int_binop( S, OpPC, Call, BuiltinID, [](const APSInt &LHS, const APSInt &RHS) { - if (RHS.uge(RHS.getBitWidth())) { - return APInt::getZero(RHS.getBitWidth()); + if (RHS.uge(LHS.getBitWidth())) { + return APInt::getZero(LHS.getBitWidth()); } return LHS.shl(RHS.getZExtValue()); }); @@ -3266,8 +3266,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, case clang::X86::BI__builtin_ia32_psrav8si: return interp__builtin_elementwise_int_binop( S, OpPC, Call, BuiltinID, [](const APSInt &LHS, const APSInt &RHS) { - if (RHS.uge(RHS.getBitWidth())) { - return LHS.ashr(RHS.getBitWidth() - 1); + if (RHS.uge(LHS.getBitWidth())) { + return LHS.ashr(LHS.getBitWidth() - 1); } return LHS.ashr(RHS.getZExtValue()); }); @@ -3278,8 +3278,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, case clang::X86::BI__builtin_ia32_psrlv8si: return interp__builtin_elementwise_int_binop( S, OpPC, Call, BuiltinID, [](const APSInt &LHS, const APSInt &RHS) { - if (RHS.uge(RHS.getBitWidth())) { - return APInt::getZero(RHS.getBitWidth()); + if (RHS.uge(LHS.getBitWidth())) { + return APInt::getZero(LHS.getBitWidth()); } return LHS.lshr(RHS.getZExtValue()); }); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
