Skip to content

Commit

Permalink
8178348: left_n_bits(0) invokes undefined behavior
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, coleenp
  • Loading branch information
Harold Seigel committed Mar 12, 2021
1 parent 0b10c6b commit 4b5c664
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
5 changes: 1 addition & 4 deletions src/hotspot/share/utilities/globalDefinitions.cpp
@@ -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
Expand Down Expand Up @@ -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));
1 change: 0 additions & 1 deletion src/hotspot/share/utilities/globalDefinitions.hpp
Expand Up @@ -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; }
Expand Down

1 comment on commit 4b5c664

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.