Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update limit constants to use numeric_limits<>::max() #3584

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ddr/lib/ddr-blobgen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2017 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -33,3 +33,7 @@ target_link_libraries(omr_ddr_blobgen
omr_ddr_macros
omr_ddr_scanner
)

target_compile_definitions(omr_ddr_blobgen
PRIVATE __STDC_LIMIT_MACROS
)
6 changes: 5 additions & 1 deletion ddr/lib/ddr-ir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2017 IBM Corp. and others
# Copyright (c) 2017, 2019 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -41,3 +41,7 @@ set_property(TARGET omr_ddr_ir PROPERTY CXX_STANDARD 11)
target_link_libraries(omr_ddr_ir
omr_ddr_base
)

target_compile_definitions(omr_ddr_ir
PRIVATE __STDC_LIMIT_MACROS
)
8 changes: 4 additions & 4 deletions fvtest/coretest/TestBytes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2018 IBM Corp. and others
* Copyright (c) 2018, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -62,7 +62,7 @@ TEST(TestBytes, IsPow2)
EXPECT_FALSE(isPow2(6));
EXPECT_FALSE(isPow2(7));
EXPECT_FALSE(isPow2(9));
EXPECT_FALSE(isPow2(SIZE_MAX));
EXPECT_FALSE(isPow2(std::numeric_limits<size_t>::max()));
}

TEST(TestBytes, AlignedUnsafe)
Expand Down Expand Up @@ -180,8 +180,8 @@ TEST(TestBytes, AlignAndOverflow)
TEST(TestBytes, AlignMaximumSizeFor16byteAlignment)
{
// hand crafted maximums for a 16 byte alignment
EXPECT_EQ(SIZE_MAX - 15, align(SIZE_MAX - 17, 16));
EXPECT_EQ(SIZE_MAX, align(SIZE_MAX, 1));
EXPECT_EQ(std::numeric_limits<size_t>::max() - 15, align(std::numeric_limits<size_t>::max() - 17, 16));
EXPECT_EQ(std::numeric_limits<size_t>::max(), align(std::numeric_limits<size_t>::max(), 1));
}

} // namespace OMR
9 changes: 5 additions & 4 deletions include_core/OMR/Bytes.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2018 IBM and others
* Copyright (c) 2018, 2019 IBM and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -27,6 +27,7 @@
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <limits>

namespace OMR
{
Expand Down Expand Up @@ -63,10 +64,10 @@ isPow2(size_t x)
}

/// The maximum safe alignment, when aligning sizes up to UNALIGNED_SIZE_MAX.
static const size_t ALIGNMENT_MAX = (SIZE_MAX >> 1) + 1;
static const size_t ALIGNMENT_MAX = (std::numeric_limits<size_t>::max() >> 1) + 1;

/// The maximum safe size, when aligning up to ALIGNMENT_MAX.
static const size_t UNALIGNED_SIZE_MAX = (SIZE_MAX >> 1) + 1;
static const size_t UNALIGNED_SIZE_MAX = (std::numeric_limits<size_t>::max() >> 1) + 1;

/// True if size is aligned to alignment. No safety checks.
/// alignment must be a power of two.
Expand Down Expand Up @@ -103,7 +104,7 @@ inline size_t
align(size_t size, size_t alignment)
{
assert(isPow2(alignment));
assert(size <= SIZE_MAX - alignment + 1); // overflow check
assert(size <= std::numeric_limits<size_t>::max() - alignment + 1); // overflow check
return alignNoCheck(size, alignment);
}

Expand Down