Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Add support for 128 bit ints in limits.h
Also, this adds unit tests to check that limits.h complies with the C standard. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D110643
- Loading branch information
1 parent
5cf0606
commit b62d72f
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===-- Unittests for Limits ----------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "utils/CPP/Limits.h" | ||
#include "utils/UnitTest/Test.h" | ||
|
||
// This just checks against the C spec, almost all implementations will surpass | ||
// this. | ||
TEST(LlvmLibcLimitsTest, LimitsFollowSpec) { | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<int>::max(), INT_MAX); | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<int>::min(), INT_MIN); | ||
|
||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned int>::max(), UINT_MAX); | ||
|
||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long>::max(), LONG_MAX); | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long>::min(), LONG_MIN); | ||
|
||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned long>::max(), ULONG_MAX); | ||
|
||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long long>::max(), LLONG_MAX); | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long long>::min(), LLONG_MIN); | ||
|
||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned long long>::max(), | ||
ULLONG_MAX); | ||
} | ||
|
||
// This checks that the current environment supports 128 bit integers. | ||
TEST(LlvmLibcLimitsTest, Int128Works) { | ||
__int128_t max128 = ~__uint128_t(0) >> 1; | ||
__int128_t min128 = (__int128_t(1) << 127); | ||
EXPECT_GT(__llvm_libc::cpp::NumericLimits<__int128_t>::max(), | ||
__int128_t(__llvm_libc::cpp::NumericLimits<long long>::max())); | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<__int128_t>::max(), max128); | ||
|
||
EXPECT_LT(__llvm_libc::cpp::NumericLimits<__int128_t>::min(), | ||
__int128_t(__llvm_libc::cpp::NumericLimits<long long>::min())); | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<__int128_t>::min(), min128); | ||
|
||
__uint128_t umax128 = ~__uint128_t(0); | ||
EXPECT_GT( | ||
__llvm_libc::cpp::NumericLimits<__uint128_t>::max(), | ||
__uint128_t(__llvm_libc::cpp::NumericLimits<unsigned long long>::max())); | ||
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<__uint128_t>::max(), umax128); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters