Commit 60644abd authored by Dean Moldovan's avatar Dean Moldovan

Fix shift-negative-value warnings

parent 3205005f
......@@ -80,7 +80,7 @@ void Assembler::emitArith(Immediate imm, Register r, int opcode) {
// assert(r != RSP && "This breaks unwinding, please don't use.");
int64_t amount = imm.val;
RELEASE_ASSERT((-1L << 31) <= amount && amount < (1L << 31) - 1, "");
RELEASE_ASSERT(fitsInto<int32_t>(amount), "");
assert(0 <= opcode && opcode < 8);
int rex = REX_W;
......@@ -183,7 +183,7 @@ void Assembler::mov(Immediate val, Register dest, bool force_64bit_load) {
void Assembler::movq(Immediate src, Indirect dest) {
int64_t src_val = src.val;
assert((-1L << 31) <= src_val && src_val < (1L << 31) - 1);
assert(fitsInto<int32_t>(src_val));
int rex = REX_W;
......@@ -739,7 +739,7 @@ void Assembler::cmp(Register reg, Immediate imm) {
void Assembler::cmp(Indirect mem, Immediate imm) {
int64_t val = imm.val;
assert((-1L << 31) <= val && val < (1L << 31) - 1);
assert(fitsInto<int32_t>(val));
int src_idx = mem.base.regnum;
......@@ -760,7 +760,7 @@ void Assembler::cmp(Indirect mem, Immediate imm) {
emitModRM(0b01, 7, src_idx);
emitByte(mem.offset);
} else {
assert((-1L << 31) <= mem.offset && mem.offset < (1L << 31) - 1);
assert(fitsInto<int32_t>(mem.offset));
emitModRM(0b10, 7, src_idx);
emitInt(mem.offset, 4);
}
......@@ -794,7 +794,7 @@ void Assembler::cmp(Indirect mem, Register reg) {
emitModRM(0b01, reg_idx, mem_idx);
emitByte(mem.offset);
} else {
assert((-1L << 31) <= mem.offset && mem.offset < (1L << 31) - 1);
assert(fitsInto<int32_t>(mem.offset));
emitModRM(0b10, reg_idx, mem_idx);
emitInt(mem.offset, 4);
}
......@@ -830,7 +830,7 @@ void Assembler::lea(Indirect mem, Register reg) {
if (mode == 0b01) {
emitByte(mem.offset);
} else if (mode == 0b10) {
assert((-1L << 31) <= mem.offset && mem.offset < (1L << 31) - 1);
assert(fitsInto<int32_t>(mem.offset));
emitInt(mem.offset, 4);
}
}
......@@ -910,7 +910,7 @@ void Assembler::jmp(Indirect dest) {
emitModRM(0b01, 0b100, reg_idx);
emitByte(dest.offset);
} else {
assert((-1L << 31) <= dest.offset && dest.offset < (1L << 31) - 1);
assert(fitsInto<int32_t>(dest.offset));
emitModRM(0b10, 0b100, reg_idx);
emitInt(dest.offset, 4);
}
......
......@@ -600,7 +600,7 @@ public:
static Rewriter* createRewriter(void* rtn_addr, int num_args, const char* debug_name);
static bool isLargeConstant(int64_t val) { return (val < (-1L << 31) || val >= (1L << 31) - 1); }
static bool isLargeConstant(int64_t val) { return !fitsInto<int32_t>(val); }
// The "aggressiveness" with which we should try to do this rewrite. It starts high, and decreases over time.
// The values are nominally in the range 0-100, with 0 being no aggressiveness and 100 being fully aggressive,
......
......@@ -172,9 +172,7 @@ struct JumpDestination {
int offset;
JumpDestination(OffsetType type, int64_t offset) : type(type), offset(offset) {
assert((-1L << 31) <= offset && offset < (1L << 31) - 1);
}
JumpDestination(OffsetType type, int64_t offset) : type(type), offset(offset) { assert(fitsInto<int32_t>(offset)); }
static JumpDestination fromStart(int offset) { return JumpDestination(FROM_START, offset); }
};
}
......
......@@ -19,6 +19,7 @@
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <stdint.h>
#include <string>
#include <unordered_map>
......@@ -82,4 +83,11 @@ template <typename T1, typename T2, typename T3> struct hash<tuple<T1, T2, T3>>
};
}
namespace pyston {
template <typename T>
constexpr bool fitsInto(int64_t x) {
return std::numeric_limits<T>::min() <= x && x < std::numeric_limits<T>::max();
}
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment