[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 Dec 6 04:34:45 PST 2023
https://github.com/madanial0 updated https://github.com/llvm/llvm-project/pull/73878
>From 6c1364ace263313114894554b22cb86dbb6983d3 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 1/3] [Flang] malloc(1) on AIX as malloc(0) returns nullptr
---
flang/runtime/ISO_Fortran_binding.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp
index ce146844533a0..20bd42adbd801 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang/runtime/ISO_Fortran_binding.cpp
@@ -75,7 +75,14 @@ RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *descriptor,
dim->sm = byteSize;
byteSize *= extent;
}
+#ifdef _AIX
+ if (!byteSize)
+ void *p{std::malloc(1)};
+ else
+ void *p{std::malloc(byteSize)};
+#else
void *p{std::malloc(byteSize)};
+#endif
if (!p && byteSize) {
return CFI_ERROR_MEM_ALLOCATION;
}
>From 3c04579d3d5f97e0f8ed3ff5bae3c79802ae3786 Mon Sep 17 00:00:00 2001
From: Mark Danial <madanial at dixon.rtp.raleigh.ibm.com>
Date: Mon, 4 Dec 2023 15:19:53 -0500
Subject: [PATCH 2/3] Address malloc(0) for all platforms
---
flang/runtime/ISO_Fortran_binding.cpp | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp
index 20bd42adbd801..13ae2b9eabdeb 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang/runtime/ISO_Fortran_binding.cpp
@@ -75,14 +75,7 @@ RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *descriptor,
dim->sm = byteSize;
byteSize *= extent;
}
-#ifdef _AIX
- if (!byteSize)
- void *p{std::malloc(1)};
- else
- void *p{std::malloc(byteSize)};
-#else
- void *p{std::malloc(byteSize)};
-#endif
+ void *p = byteSize ? std::malloc(byteSize) : std::malloc(1);
if (!p && byteSize) {
return CFI_ERROR_MEM_ALLOCATION;
}
>From bb948ad4cce8d3fe3af3f62aff807728fe3dcf08 Mon Sep 17 00:00:00 2001
From: Mark Danial <madanial at dixon.rtp.raleigh.ibm.com>
Date: Tue, 5 Dec 2023 09:47:49 -0500
Subject: [PATCH 3/3] use braces for initialization
---
flang/runtime/ISO_Fortran_binding.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang/runtime/ISO_Fortran_binding.cpp
index 13ae2b9eabdeb..99ba3aa56feee 100644
--- a/flang/runtime/ISO_Fortran_binding.cpp
+++ b/flang/runtime/ISO_Fortran_binding.cpp
@@ -75,7 +75,7 @@ RT_API_ATTRS int CFI_allocate(CFI_cdesc_t *descriptor,
dim->sm = byteSize;
byteSize *= extent;
}
- void *p = byteSize ? std::malloc(byteSize) : std::malloc(1);
+ void *p{byteSize ? std::malloc(byteSize) : std::malloc(1)};
if (!p && byteSize) {
return CFI_ERROR_MEM_ALLOCATION;
}
More information about the flang-commits
mailing list