[flang-commits] [flang] [Flang] malloc(1) on AIX as malloc(0) returns nullptr (PR #73878)
via flang-commits
flang-commits at lists.llvm.org
Wed Nov 29 16:22:37 PST 2023
https://github.com/madanial0 created https://github.com/llvm/llvm-project/pull/73878
On AIX malloc(0) reutrns nullptr, which fails test case `Evaluate/ISO-Fortran-binding.test`, using malloc(1) in AIX for consistent behaviour
>From 2606c187775afa076403e68e5a88e7783c5997e4 Mon Sep 17 00:00:00 2001
From: Mark Danial <madanial at dixon.rtp.raleigh.ibm.com>
Date: Tue, 28 Nov 2023 22:14:54 -0500
Subject: [PATCH] [Flang] malloc(1) on AIX as malloc(0) returns nullptr
---
flang/runtime/ISO_Fortran_binding.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp
index ce146844533a064..f354430d6106fb9 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang/runtime/ISO_Fortran_binding.cpp
@@ -75,7 +75,11 @@ RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *descriptor,
dim->sm = byteSize;
byteSize *= extent;
}
- void *p{std::malloc(byteSize)};
+ void *p;
+ if (_AIX && !byteSize)
+ p = std::malloc(1);
+ else
+ p = std::malloc(byteSize);
if (!p && byteSize) {
return CFI_ERROR_MEM_ALLOCATION;
}
More information about the flang-commits
mailing list