llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Ilia Kuklin (kuilpd) <details> <summary>Changes</summary> `Scalar` produced an invalid value when detecting any division by zero. This should be only for integer division. --- Full diff: https://github.com/llvm/llvm-project/pull/158115.diff 2 Files Affected: - (modified) lldb/source/Utility/Scalar.cpp (+3-2) - (modified) lldb/unittests/Utility/ScalarTest.cpp (+6) ``````````diff diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp index 7fbe46d46194f..c8766bdf2aee7 100644 --- a/lldb/source/Utility/Scalar.cpp +++ b/lldb/source/Utility/Scalar.cpp @@ -565,12 +565,13 @@ const Scalar lldb_private::operator-(Scalar lhs, Scalar rhs) { const Scalar lldb_private::operator/(Scalar lhs, Scalar rhs) { Scalar result; - if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void && - !rhs.IsZero()) { + if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) { switch (result.m_type) { case Scalar::e_void: break; case Scalar::e_int: + if (rhs.IsZero()) + break; result.m_integer = lhs.m_integer / rhs.m_integer; return result; case Scalar::e_float: diff --git a/lldb/unittests/Utility/ScalarTest.cpp b/lldb/unittests/Utility/ScalarTest.cpp index 256d456783583..6d5caef42bee4 100644 --- a/lldb/unittests/Utility/ScalarTest.cpp +++ b/lldb/unittests/Utility/ScalarTest.cpp @@ -337,6 +337,12 @@ TEST(ScalarTest, Division) { Scalar r = lhs / rhs; EXPECT_TRUE(r.IsValid()); EXPECT_EQ(r, Scalar(2.5)); + + Scalar inf = Scalar(1) / Scalar(0.0f); + Scalar int0 = Scalar(1) / Scalar(0); + Scalar ref_inf = llvm::APFloat::getInf(llvm::APFloat::IEEEsingle()); + EXPECT_EQ(inf, ref_inf); + EXPECT_FALSE(int0.IsValid()); } TEST(ScalarTest, Promotion) { `````````` </details> https://github.com/llvm/llvm-project/pull/158115 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
