From 5b71b1337be3e9005e8e5c5d1c00eb1ea1b62fa7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 1 May 2018 11:58:13 -0400 Subject: [PATCH] emit_x64_vector: Avoid left shift of negative value in LogicalVShift Now that we handle the signed variants, we also have to be careful about left shifts with negative values, as this is considered undefined behavior. --- src/backend_x64/emit_x64_vector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend_x64/emit_x64_vector.cpp b/src/backend_x64/emit_x64_vector.cpp index 26a5f006..b43d9468 100644 --- a/src/backend_x64/emit_x64_vector.cpp +++ b/src/backend_x64/emit_x64_vector.cpp @@ -945,7 +945,8 @@ static constexpr T LogicalVShift(T x, T y) { return x >> T(-shift_amount); } - return x << T(shift_amount); + using unsigned_type = std::make_unsigned_t; + return static_cast(static_cast(x) << static_cast(shift_amount)); } void EmitX64::EmitVectorLogicalVShiftS8(EmitContext& ctx, IR::Inst* inst) {