Skip to content
Permalink
Browse files
8178348: left_n_bits(0) invokes undefined behavior
Reviewed-by: dholmes, coleenp
  • Loading branch information
Harold Seigel committed Mar 12, 2021
1 parent 0b10c6b commit 4b5c664b4cb3700331b80096fff3c3bebd49835f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -390,6 +390,3 @@ STATIC_ASSERT(nth_bit(1|2) == 0x8);

STATIC_ASSERT(right_n_bits(3) == 0x7);
STATIC_ASSERT(right_n_bits(1|2) == 0x7);

STATIC_ASSERT(left_n_bits(3) == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
STATIC_ASSERT(left_n_bits(1|2) == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
@@ -982,7 +982,6 @@ const intptr_t OneBit = 1; // only right_most bit set in a word
// (note: #define used only so that they can be used in enum constant definitions)
#define nth_bit(n) (((n) >= BitsPerWord) ? 0 : (OneBit << (n)))
#define right_n_bits(n) (nth_bit(n) - 1)
#define left_n_bits(n) (right_n_bits(n) << (((n) >= BitsPerWord) ? 0 : (BitsPerWord - (n))))

// bit-operations using a mask m
inline void set_bits (intptr_t& x, intptr_t m) { x |= m; }

0 comments on commit 4b5c664

Please sign in to comment.