summaryrefslogtreecommitdiffstats
path: root/lldb/unittests
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2018-04-02 16:50:54 +0000
committerDavide Italiano <davide@freebsd.org>2018-04-02 16:50:54 +0000
commit49d802862d5edf762928cb2ee159614f31eb2364 (patch)
treef95222a9cd1a0b4f3ea8e03fc4e39ef3b28de04d /lldb/unittests
parentf4e7e5210cd70b13a90e2a876eaadb7f02ef5829 (diff)
downloadbcm5719-llvm-49d802862d5edf762928cb2ee159614f31eb2364.tar.gz
bcm5719-llvm-49d802862d5edf762928cb2ee159614f31eb2364.zip
[Core] Grab-bag of improvements for Scalar.
Remove Scalar::Cast. It was noted on the list that this method is unused. So, this patch removes it. Fix Scalar::Promote for most integer types This fixes promotion of most integer types (128- and 256-bit types are handled in a subsequent patch) to floating-point types. Previously promotion was done bitwise, where value preservation is correct. Fix Scalar::Promote for 128- and 256-bit integer types This patch fixes the behavior of Scalar::Promote when trying to perform a binary operation involving a 128- or 256-bit integer type and a floating-point type. Now, the integer is cast to the floating point type for the operation. Patch by Tom Tromey! Differential Revision: https://reviews.llvm.org/D44907 llvm-svn: 328985
Diffstat (limited to 'lldb/unittests')
-rw-r--r--lldb/unittests/Core/ScalarTest.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lldb/unittests/Core/ScalarTest.cpp b/lldb/unittests/Core/ScalarTest.cpp
index 47fa0215ead..6ccc3907064 100644
--- a/lldb/unittests/Core/ScalarTest.cpp
+++ b/lldb/unittests/Core/ScalarTest.cpp
@@ -73,6 +73,12 @@ TEST(ScalarTest, CastOperations) {
ASSERT_EQ((unsigned long)a, a_scalar.ULong());
ASSERT_EQ((signed long long)a, a_scalar.SLongLong());
ASSERT_EQ((unsigned long long)a, a_scalar.ULongLong());
+
+ int a2 = 23;
+ Scalar a2_scalar(a2);
+ ASSERT_EQ((float)a2, a2_scalar.Float());
+ ASSERT_EQ((double)a2, a2_scalar.Double());
+ ASSERT_EQ((long double)a2, a2_scalar.LongDouble());
}
TEST(ScalarTest, ExtractBitfield) {
@@ -140,3 +146,42 @@ TEST(ScalarTest, Division) {
EXPECT_TRUE(r.IsValid());
EXPECT_EQ(r, Scalar(2.5));
}
+
+TEST(ScalarTest, Promotion) {
+ static Scalar::Type int_types[] = {
+ Scalar::e_sint, Scalar::e_uint, Scalar::e_slong,
+ Scalar::e_ulong, Scalar::e_slonglong, Scalar::e_ulonglong,
+ Scalar::e_sint128, Scalar::e_uint128, Scalar::e_sint256,
+ Scalar::e_uint256,
+ Scalar::e_void // sentinel
+ };
+
+ static Scalar::Type float_types[] = {
+ Scalar::e_float, Scalar::e_double, Scalar::e_long_double,
+ Scalar::e_void // sentinel
+ };
+
+ for (int i = 0; int_types[i] != Scalar::e_void; ++i) {
+ for (int j = 0; float_types[j] != Scalar::e_void; ++j) {
+ Scalar lhs(2);
+ EXPECT_TRUE(lhs.Promote(int_types[i])) << "int promotion #" << i;
+ Scalar rhs(0.5f);
+ EXPECT_TRUE(rhs.Promote(float_types[j])) << "float promotion #" << j;
+ Scalar x(2.5f);
+ EXPECT_TRUE(x.Promote(float_types[j]));
+ EXPECT_EQ(lhs + rhs, x);
+ }
+ }
+
+ for (int i = 0; float_types[i] != Scalar::e_void; ++i) {
+ for (int j = 0; float_types[j] != Scalar::e_void; ++j) {
+ Scalar lhs(2);
+ EXPECT_TRUE(lhs.Promote(float_types[i])) << "float promotion #" << i;
+ Scalar rhs(0.5f);
+ EXPECT_TRUE(rhs.Promote(float_types[j])) << "float promotion #" << j;
+ Scalar x(2.5f);
+ EXPECT_TRUE(x.Promote(float_types[j]));
+ EXPECT_EQ(lhs + rhs, x);
+ }
+ }
+}
OpenPOWER on IntegriCloud