Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang] malloc(1) on AIX as malloc(0) returns nullptr #73878

Merged
merged 3 commits into from
Dec 6, 2023

Conversation

madanial0
Copy link
Contributor

On AIX malloc(0) reutrns nullptr, which fails test case Evaluate/ISO-Fortran-binding.test, using malloc(1) in AIX for consistent behaviour

@madanial0 madanial0 added the flang Flang issues not falling into any other category label Nov 30, 2023
@madanial0 madanial0 self-assigned this Nov 30, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 30, 2023

@llvm/pr-subscribers-flang-runtime

Author: None (madanial0)

Changes

On AIX malloc(0) reutrns nullptr, which fails test case Evaluate/ISO-Fortran-binding.test, using malloc(1) in AIX for consistent behaviour


Full diff: https://github.com/llvm/llvm-project/pull/73878.diff

1 Files Affected:

  • (modified) flang/runtime/ISO_Fortran_binding.cpp (+5-1)
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;
   }

Copy link

github-actions bot commented Nov 30, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@madanial0 madanial0 marked this pull request as ready for review November 30, 2023 03:49
Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@madanial0 madanial0 merged commit ef2d59b into llvm:main Dec 6, 2023
4 checks passed
@madanial0 madanial0 deleted the mallocAIX branch December 6, 2023 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants