mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-07 02:30:17 +00:00
remove an UB
This commit is contained in:
parent
4ba44fa51b
commit
9c9faa5f89
@ -20,7 +20,7 @@
|
||||
#include <typeindex>
|
||||
#include <initializer_list>
|
||||
|
||||
#define PK_VERSION "1.4.5"
|
||||
#define PK_VERSION "1.4.6"
|
||||
|
||||
#include "config.h"
|
||||
#include "export.h"
|
||||
@ -70,26 +70,18 @@ namespace std = ::std;
|
||||
template <size_t T>
|
||||
struct NumberTraits;
|
||||
|
||||
inline constexpr bool is_negative_shift_well_defined(){
|
||||
#ifdef __EMSCRIPTEN__
|
||||
return false;
|
||||
#endif
|
||||
// rshift does not affect the sign bit
|
||||
return -1 >> 1 == -1;
|
||||
}
|
||||
|
||||
template <>
|
||||
struct NumberTraits<4> {
|
||||
using int_t = int32_t;
|
||||
static constexpr int_t kMaxSmallInt = (1 << 28) - 1;
|
||||
static constexpr int_t kMinSmallInt = is_negative_shift_well_defined() ? -(1 << 28) : 0;
|
||||
static constexpr int_t kMinSmallInt = 0;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct NumberTraits<8> {
|
||||
using int_t = int64_t;
|
||||
static constexpr int_t kMaxSmallInt = (1ll << 60) - 1;
|
||||
static constexpr int_t kMinSmallInt = is_negative_shift_well_defined() ? -(1ll << 60) : 0;
|
||||
static constexpr int_t kMinSmallInt = 0;
|
||||
};
|
||||
|
||||
using Number = NumberTraits<sizeof(void*)>;
|
||||
|
||||
@ -14,11 +14,6 @@ OPCODE(LOAD_NONE)
|
||||
OPCODE(LOAD_TRUE)
|
||||
OPCODE(LOAD_FALSE)
|
||||
/**************************/
|
||||
OPCODE(LOAD_INT_NEG_5)
|
||||
OPCODE(LOAD_INT_NEG_4)
|
||||
OPCODE(LOAD_INT_NEG_3)
|
||||
OPCODE(LOAD_INT_NEG_2)
|
||||
OPCODE(LOAD_INT_NEG_1)
|
||||
OPCODE(LOAD_INT_0)
|
||||
OPCODE(LOAD_INT_1)
|
||||
OPCODE(LOAD_INT_2)
|
||||
|
||||
@ -119,11 +119,6 @@ __NEXT_STEP:;
|
||||
TARGET(LOAD_TRUE) PUSH(True); DISPATCH();
|
||||
TARGET(LOAD_FALSE) PUSH(False); DISPATCH();
|
||||
/*****************************************/
|
||||
TARGET(LOAD_INT_NEG_5) PUSH((PyObject*)-18); DISPATCH();
|
||||
TARGET(LOAD_INT_NEG_4) PUSH((PyObject*)-14); DISPATCH();
|
||||
TARGET(LOAD_INT_NEG_3) PUSH((PyObject*)-10); DISPATCH();
|
||||
TARGET(LOAD_INT_NEG_2) PUSH((PyObject*)-6); DISPATCH();
|
||||
TARGET(LOAD_INT_NEG_1) PUSH((PyObject*)-2); DISPATCH();
|
||||
TARGET(LOAD_INT_0) PUSH(PK_SMALL_INT(0)); DISPATCH();
|
||||
TARGET(LOAD_INT_1) PUSH(PK_SMALL_INT(1)); DISPATCH();
|
||||
TARGET(LOAD_INT_2) PUSH(PK_SMALL_INT(2)); DISPATCH();
|
||||
|
||||
@ -86,9 +86,8 @@ namespace pkpy{
|
||||
}
|
||||
|
||||
int CodeEmitContext::emit_int(i64 value, int line){
|
||||
bool allow_neg_int = is_negative_shift_well_defined() || value >= 0;
|
||||
if(allow_neg_int && value >= -5 && value <= 16){
|
||||
uint8_t op = OP_LOAD_INT_NEG_5 + (uint8_t)value + 5;
|
||||
if(value >= 0 && value <= 16){
|
||||
uint8_t op = OP_LOAD_INT_0 + (uint8_t)value;
|
||||
return emit_((Opcode)op, BC_NOARG, line);
|
||||
}else{
|
||||
return emit_(OP_LOAD_CONST, add_const(VAR(value)), line);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user