[flang-commits] [flang] [flang] Use std::uintptr_t instead of unsigned long for better cross-… (PR #183913)
via flang-commits
flang-commits at lists.llvm.org
Sat Feb 28 05:15:07 PST 2026
https://github.com/dragon-archer created https://github.com/llvm/llvm-project/pull/183913
…platform stability
Originally, the specialization hardcode unsigned long, and add another specialization of unsigned __int64 for MSVC. This is redundant, and will fails when compiling on MSYS2 (where uintptr_t is unsigned long long)
>From cf1be87061457402620f3211b9d5587e57c1f801 Mon Sep 17 00:00:00 2001
From: dragon-archer <dragon-archer at outlook.com>
Date: Sat, 28 Feb 2026 21:13:20 +0800
Subject: [PATCH] [flang] Use std::uintptr_t instead of unsigned long for
better cross-platform stability
Originally, the specialization hardcode unsigned long, and add another specialization of unsigned __int64 for MSVC. This is redundant, and will fails when compiling on MSYS2 (where uintptr_t is unsigned long long)
---
.../Optimizer/Builder/Runtime/RTBuilder.h | 22 ++++---------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index 2c74ab29f75e8..db36d56156275 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -253,31 +253,17 @@ constexpr TypeBuilderFunc getModel<void (*)(int)>() {
}
template <>
constexpr TypeBuilderFunc
-getModel<void *(*)(void *, const void *, unsigned long)>() {
+getModel<void *(*)(void *, const void *, std::uintptr_t)>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
auto voidPtrTy =
fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8));
- auto unsignedLongTy =
- mlir::IntegerType::get(context, 8 * sizeof(unsigned long));
+ auto uintPtrTy =
+ mlir::IntegerType::get(context, 8 * sizeof(std::uintptr_t));
auto funcTy = mlir::FunctionType::get(
- context, {voidPtrTy, voidPtrTy, unsignedLongTy}, {voidPtrTy});
+ context, {voidPtrTy, voidPtrTy, uintPtrTy}, {voidPtrTy});
return fir::LLVMPointerType::get(context, funcTy);
};
}
-#ifdef _MSC_VER
-template <>
-constexpr TypeBuilderFunc
-getModel<void *(*)(void *, const void *, unsigned __int64)>() {
- return [](mlir::MLIRContext *context) -> mlir::Type {
- auto voidPtrTy =
- fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8));
- auto uint64Ty = mlir::IntegerType::get(context, 64);
- auto funcTy = mlir::FunctionType::get(
- context, {voidPtrTy, voidPtrTy, uint64Ty}, {voidPtrTy});
- return fir::LLVMPointerType::get(context, funcTy);
- };
-}
-#endif
template <>
constexpr TypeBuilderFunc getModel<void (*)(void)>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
More information about the flang-commits
mailing list