[flang-commits] [flang] [flang] Fix the memcpy function type model for MinGW-w64 (PR #233251)

Daisuke Nishimatsu via flang-commits flang-commits at lists.llvm.org
Sun Oct 18 08:59:33 PDT 2026


https://github.com/wep21 created https://github.com/llvm/llvm-project/pull/233251

`RTBuilder.h` needs a `getModel` specialization for the runtime's `MemcpyFct` type, `void *(*)(void *, const void *, std::size_t)`, that matches `std::size_t`. On 64-bit Windows `std::size_t` is `unsigned long long`, but that specialization was guarded by `_MSC_VER`, so building flang for MinGW-w64 (windows-gnu) failed to link:

```
ld.lld: error: undefined symbol: mlir::Type (*fir::runtime::getModel<void* (*)(void*, void const*, unsigned long long)>())(mlir::MLIRContext*)
```

Guard it by `_WIN32`, which MSVC, clang-cl and MinGW-w64 all define, and spell the type `unsigned long long`, the same type as `unsigned __int64` under MSVC. MSVC and non-Windows builds are unchanged.

Tested by cross-compiling flang for `x86_64-w64-windows-gnu` from LLVM 23.1.2, which fails to link without this change and links with it.

Assisted-by: Claude Code


>From f890dfd75dfee1142e50621a15248e9af03d193e Mon Sep 17 00:00:00 2001
From: wep21 <daisuke.nishimatsu1021 at gmail.com>
Date: Sun, 18 Oct 2026 15:11:42 +0900
Subject: [PATCH] [flang] Fix the memcpy function type model for MinGW-w64

---
 flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index 67bdf6867251a5..180e5fe8ae5784 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -266,10 +266,10 @@ getModel<void *(*)(void *, const void *, unsigned long)>() {
     return fir::LLVMPointerType::get(context, funcTy);
   };
 }
-#ifdef _MSC_VER
+#ifdef _WIN32
 template <>
 constexpr TypeBuilderFunc
-getModel<void *(*)(void *, const void *, unsigned __int64)>() {
+getModel<void *(*)(void *, const void *, unsigned long long)>() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
     auto voidPtrTy =
         fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8));



More information about the flang-commits mailing list