[llvm] [Flang-RT][unittests] Fix buffer overflow (PR #182176)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 18 14:54:08 PST 2026


https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/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 uninitialized memory when accessing the additional 4 elements. In most cases the additional values get gobbled up by the inifinty, but if it happens to be NaN or the opposite 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](https://lab.llvm.org/buildbot/#/builders/166) buildbot.

>From 8dd25807b8d631a8bcadf0c112fb55daa7f3b00a Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 18 Feb 2026 23:39:36 +0100
Subject: [PATCH] [Flang-RT][unittests] Fix buffer overflow

---
 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 b03bd72bb371e..821d89f41ba7e 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<float>::infinity()};
   auto inf0{MakeArray<TypeCategory::Real, 4>(
-      std::vector<int>{2, 3}, std::vector<float>{inf, 0.0f})};
+      std::vector<int>{2}, std::vector<float>{inf, 0.0f})};
   auto t1{RTNAME(SumReal4)(*inf0, __FILE__, __LINE__)};
   EXPECT_EQ(t1, inf) << t1;
   auto infMinusInf{MakeArray<TypeCategory::Real, 4>(
-      std::vector<int>{2, 3}, std::vector<float>{inf, -inf})};
+      std::vector<int>{2}, std::vector<float>{inf, -inf})};
   auto t2{RTNAME(SumReal4)(*infMinusInf, __FILE__, __LINE__)};
   EXPECT_NE(t2, t2) << t2;
   auto minusInfInf{MakeArray<TypeCategory::Real, 4>(
-      std::vector<int>{2, 3}, std::vector<float>{-inf, inf})};
+      std::vector<int>{2}, std::vector<float>{-inf, inf})};
   auto t3{RTNAME(SumReal4)(*infMinusInf, __FILE__, __LINE__)};
   EXPECT_NE(t3, t3) << t3;
 }



More information about the llvm-commits mailing list