From f70914aaa975f0311c263a71b9acb24dc4ac719c Mon Sep 17 00:00:00 2001 From: Nir Cohen Date: Mon, 29 Sep 2025 20:22:37 +0300 Subject: [PATCH 1/2] fix template compilation issue in flang-rt, fix issue #160534 --- flang-rt/lib/runtime/matmul-transpose.cpp | 8 ++++---- flang-rt/lib/runtime/matmul.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/flang-rt/lib/runtime/matmul-transpose.cpp b/flang-rt/lib/runtime/matmul-transpose.cpp index 789f13c585ec5..29ba6a8915f2e 100644 --- a/flang-rt/lib/runtime/matmul-transpose.cpp +++ b/flang-rt/lib/runtime/matmul-transpose.cpp @@ -62,7 +62,7 @@ inline static RT_API_ATTRS void MatrixTransposedTimesMatrix( std::size_t yColumnByteStride = 0) { using ResultType = CppTypeFor; - Fortran::runtime::memset(product, 0, rows * cols * sizeof *product); + std::memset(product, 0, rows * cols * sizeof *product); for (SubscriptValue j{0}; j < cols; ++j) { for (SubscriptValue i{0}; i < rows; ++i) { for (SubscriptValue k{0}; k < n; ++k) { @@ -132,7 +132,7 @@ inline static RT_API_ATTRS void MatrixTransposedTimesVector( SubscriptValue n, const XT *RESTRICT x, const YT *RESTRICT y, std::size_t xColumnByteStride = 0) { using ResultType = CppTypeFor; - Fortran::runtime::memset(product, 0, rows * sizeof *product); + std::memset(product, 0, rows * sizeof *product); for (SubscriptValue i{0}; i < rows; ++i) { for (SubscriptValue k{0}; k < n; ++k) { ResultType x_ki; @@ -340,8 +340,8 @@ struct MatmulTransposeHelper { RUNTIME_CHECK(terminator, xCatKind.has_value() && yCatKind.has_value()); RUNTIME_CHECK(terminator, xCatKind->first == XCAT); RUNTIME_CHECK(terminator, yCatKind->first == YCAT); - if constexpr (constexpr ResultTy resultType{ - GetResultType(XCAT, XKIND, YCAT, YKIND)}) { + constexpr ResultTy resultType{GetResultType(XCAT, XKIND, YCAT, YKIND)}; + if constexpr (resultType) { return DoMatmulTransposefirst, resultType->second, CppTypeFor, CppTypeFor>( result, x, y, terminator); diff --git a/flang-rt/lib/runtime/matmul.cpp b/flang-rt/lib/runtime/matmul.cpp index d409cb1458c90..0e398c018d55d 100644 --- a/flang-rt/lib/runtime/matmul.cpp +++ b/flang-rt/lib/runtime/matmul.cpp @@ -81,7 +81,7 @@ inline RT_API_ATTRS void MatrixTimesMatrix( SubscriptValue n, std::size_t xColumnByteStride = 0, std::size_t yColumnByteStride = 0) { using ResultType = CppTypeFor; - Fortran::runtime::memset(product, 0, rows * cols * sizeof *product); + std::memset(product, 0, rows * cols * sizeof *product); const XT *RESTRICT xp0{x}; for (SubscriptValue k{0}; k < n; ++k) { ResultType *RESTRICT p{product}; @@ -153,7 +153,7 @@ inline RT_API_ATTRS void MatrixTimesVector( SubscriptValue n, const XT *RESTRICT x, const YT *RESTRICT y, std::size_t xColumnByteStride = 0) { using ResultType = CppTypeFor; - Fortran::runtime::memset(product, 0, rows * sizeof *product); + std::memset(product, 0, rows * sizeof *product); [[maybe_unused]] const XT *RESTRICT xp0{x}; for (SubscriptValue k{0}; k < n; ++k) { ResultType *RESTRICT p{product}; @@ -203,7 +203,7 @@ inline RT_API_ATTRS void VectorTimesMatrix( SubscriptValue cols, const XT *RESTRICT x, const YT *RESTRICT y, std::size_t yColumnByteStride = 0) { using ResultType = CppTypeFor; - Fortran::runtime::memset(product, 0, cols * sizeof *product); + std::memset(product, 0, cols * sizeof *product); for (SubscriptValue k{0}; k < n; ++k) { ResultType *RESTRICT p{product}; auto xv{static_cast(*x++)}; @@ -440,8 +440,8 @@ struct MatmulHelper { xCatKind->first == TypeCategory::Unsigned) && (yCatKind->first == TypeCategory::Integer || yCatKind->first == TypeCategory::Unsigned)))); - if constexpr (constexpr ResultTy resultType{ - GetResultType(XCAT, XKIND, YCAT, YKIND)}) { + constexpr ResultTy resultType{GetResultType(XCAT, XKIND, YCAT, YKIND)}; + if constexpr (resultType) { return DoMatmulfirst, resultType->second, CppTypeFor, CppTypeFor>( result, x, y, terminator); From 8f60ffd3fd4592664742cebb8c4721d37c46abf3 Mon Sep 17 00:00:00 2001 From: Nir Cohen Date: Sat, 4 Oct 2025 15:56:24 +0300 Subject: [PATCH 2/2] fix memset to use freestanding tool instead of stdlib --- flang-rt/lib/runtime/matmul-transpose.cpp | 4 ++-- flang-rt/lib/runtime/matmul.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flang-rt/lib/runtime/matmul-transpose.cpp b/flang-rt/lib/runtime/matmul-transpose.cpp index 29ba6a8915f2e..c2efe30a49e46 100644 --- a/flang-rt/lib/runtime/matmul-transpose.cpp +++ b/flang-rt/lib/runtime/matmul-transpose.cpp @@ -62,7 +62,7 @@ inline static RT_API_ATTRS void MatrixTransposedTimesMatrix( std::size_t yColumnByteStride = 0) { using ResultType = CppTypeFor; - std::memset(product, 0, rows * cols * sizeof *product); + Fortran::runtime::memset(product, 0, rows * cols * sizeof *product); for (SubscriptValue j{0}; j < cols; ++j) { for (SubscriptValue i{0}; i < rows; ++i) { for (SubscriptValue k{0}; k < n; ++k) { @@ -132,7 +132,7 @@ inline static RT_API_ATTRS void MatrixTransposedTimesVector( SubscriptValue n, const XT *RESTRICT x, const YT *RESTRICT y, std::size_t xColumnByteStride = 0) { using ResultType = CppTypeFor; - std::memset(product, 0, rows * sizeof *product); + Fortran::runtime::memset(product, 0, rows * sizeof *product); for (SubscriptValue i{0}; i < rows; ++i) { for (SubscriptValue k{0}; k < n; ++k) { ResultType x_ki; diff --git a/flang-rt/lib/runtime/matmul.cpp b/flang-rt/lib/runtime/matmul.cpp index 0e398c018d55d..611935a1c8e1b 100644 --- a/flang-rt/lib/runtime/matmul.cpp +++ b/flang-rt/lib/runtime/matmul.cpp @@ -81,7 +81,7 @@ inline RT_API_ATTRS void MatrixTimesMatrix( SubscriptValue n, std::size_t xColumnByteStride = 0, std::size_t yColumnByteStride = 0) { using ResultType = CppTypeFor; - std::memset(product, 0, rows * cols * sizeof *product); + Fortran::runtime::memset(product, 0, rows * cols * sizeof *product); const XT *RESTRICT xp0{x}; for (SubscriptValue k{0}; k < n; ++k) { ResultType *RESTRICT p{product}; @@ -153,7 +153,7 @@ inline RT_API_ATTRS void MatrixTimesVector( SubscriptValue n, const XT *RESTRICT x, const YT *RESTRICT y, std::size_t xColumnByteStride = 0) { using ResultType = CppTypeFor; - std::memset(product, 0, rows * sizeof *product); + Fortran::runtime::memset(product, 0, rows * sizeof *product); [[maybe_unused]] const XT *RESTRICT xp0{x}; for (SubscriptValue k{0}; k < n; ++k) { ResultType *RESTRICT p{product}; @@ -203,7 +203,7 @@ inline RT_API_ATTRS void VectorTimesMatrix( SubscriptValue cols, const XT *RESTRICT x, const YT *RESTRICT y, std::size_t yColumnByteStride = 0) { using ResultType = CppTypeFor; - std::memset(product, 0, cols * sizeof *product); + Fortran::runtime::memset(product, 0, cols * sizeof *product); for (SubscriptValue k{0}; k < n; ++k) { ResultType *RESTRICT p{product}; auto xv{static_cast(*x++)};