Skip to content

Commit 0d9c0ce

Browse files
authored
[clang][x86] Ensure we use the shifted value bit width to check for out of bounds per-element shift amounts (#156019)
This should allow us to reuse these cases for the shift-by-immediate builtins in #155542
1 parent 49f39b3 commit 0d9c0ce

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,8 +3256,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32563256
case clang::X86::BI__builtin_ia32_psllv8si:
32573257
return interp__builtin_elementwise_int_binop(
32583258
S, OpPC, Call, BuiltinID, [](const APSInt &LHS, const APSInt &RHS) {
3259-
if (RHS.uge(RHS.getBitWidth())) {
3260-
return APInt::getZero(RHS.getBitWidth());
3259+
if (RHS.uge(LHS.getBitWidth())) {
3260+
return APInt::getZero(LHS.getBitWidth());
32613261
}
32623262
return LHS.shl(RHS.getZExtValue());
32633263
});
@@ -3266,8 +3266,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32663266
case clang::X86::BI__builtin_ia32_psrav8si:
32673267
return interp__builtin_elementwise_int_binop(
32683268
S, OpPC, Call, BuiltinID, [](const APSInt &LHS, const APSInt &RHS) {
3269-
if (RHS.uge(RHS.getBitWidth())) {
3270-
return LHS.ashr(RHS.getBitWidth() - 1);
3269+
if (RHS.uge(LHS.getBitWidth())) {
3270+
return LHS.ashr(LHS.getBitWidth() - 1);
32713271
}
32723272
return LHS.ashr(RHS.getZExtValue());
32733273
});
@@ -3278,8 +3278,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
32783278
case clang::X86::BI__builtin_ia32_psrlv8si:
32793279
return interp__builtin_elementwise_int_binop(
32803280
S, OpPC, Call, BuiltinID, [](const APSInt &LHS, const APSInt &RHS) {
3281-
if (RHS.uge(RHS.getBitWidth())) {
3282-
return APInt::getZero(RHS.getBitWidth());
3281+
if (RHS.uge(LHS.getBitWidth())) {
3282+
return APInt::getZero(LHS.getBitWidth());
32833283
}
32843284
return LHS.lshr(RHS.getZExtValue());
32853285
});

0 commit comments

Comments
 (0)