Skip to content

Commit

Permalink
Use uintptr_t to avoid bit operations on signed integers
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Aug 19, 2024
1 parent 977ac57 commit 25cf2a8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/vmobjects/ObjectFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@
#define TAG_INTEGER(X) \
(((X) >= VMTAGGEDINTEGER_MIN && (X) <= VMTAGGEDINTEGER_MAX && \
Universe::NewInteger(0)) \
? ((vm_oop_t)(((X) << 1) | 1)) \
? ((vm_oop_t)(((X) << 1U) | 1U)) \
: (Universe::NewInteger(X)))
#else
#define TAG_INTEGER(X) \
(((X) >= VMTAGGEDINTEGER_MIN && (X) <= VMTAGGEDINTEGER_MAX) \
? ((vm_oop_t)((((uint64_t)(X)) << 1) | 1U)) \
? ((vm_oop_t)((((uintptr_t)(X)) << 1U) | 1U)) \
: (Universe::NewInteger(X)))
#endif

#if USE_TAGGING
#define INT_VAL(X) \
(IS_TAGGED(X) ? ((int64_t)(X) >> 1) \
#define INT_VAL(X) \
(IS_TAGGED(X) ? ((int64_t)(X) >> 1U) /* NOLINT (hicpp-signed-bitwise) */ \
: (((VMInteger*)(X))->GetEmbeddedInteger()))
#define NEW_INT(X) (TAG_INTEGER((X)))
#define IS_TAGGED(X) ((int64_t)(X) & 1)
#define IS_TAGGED(X) ((bool)((uintptr_t)(X) & 1U))
#define CLASS_OF(X) \
(IS_TAGGED(X) ? load_ptr(integerClass) \
: ((AbstractVMObject*)(X))->GetClass())
Expand Down

0 comments on commit 25cf2a8

Please sign in to comment.