From 398bd9543b2a87bf5298a13f5da2f7e761af6bef Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Fri, 20 Feb 2026 09:31:39 +0100 Subject: [PATCH] [Flang-RT][unittests] Fix buffer over-read (#182176) The unittests `Reductions.InfSums` defines a test array descriptor with shape 2x3 (i.e. 6 elements), but only provides values for 2 elements. The result is access of likely uninitialized memory when accessing the additional 4 elements. In most cases the additional values get gobbled up by the infinity, but if it happens to be NaN or the negated infinity, the result becomes NaN and fails the test. Fix by reducing the shabe of the test array to 2. Fixes the flakyness of the test of the flang-x86_64-windows buildbot. --- flang-rt/unittests/Runtime/Reduction.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang-rt/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp index b03bd72bb371..821d89f41ba7 100644 --- a/flang-rt/unittests/Runtime/Reduction.cpp +++ b/flang-rt/unittests/Runtime/Reduction.cpp @@ -676,15 +676,15 @@ TEST(Reductions, ReduceInt4Dim) { TEST(Reductions, InfSums) { auto inf{std::numeric_limits::infinity()}; auto inf0{MakeArray( - std::vector{2, 3}, std::vector{inf, 0.0f})}; + std::vector{2}, std::vector{inf, 0.0f})}; auto t1{RTNAME(SumReal4)(*inf0, __FILE__, __LINE__)}; EXPECT_EQ(t1, inf) << t1; auto infMinusInf{MakeArray( - std::vector{2, 3}, std::vector{inf, -inf})}; + std::vector{2}, std::vector{inf, -inf})}; auto t2{RTNAME(SumReal4)(*infMinusInf, __FILE__, __LINE__)}; EXPECT_NE(t2, t2) << t2; auto minusInfInf{MakeArray( - std::vector{2, 3}, std::vector{-inf, inf})}; + std::vector{2}, std::vector{-inf, inf})}; auto t3{RTNAME(SumReal4)(*infMinusInf, __FILE__, __LINE__)}; EXPECT_NE(t3, t3) << t3; }