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] allow _POSIX_SOURCE to be defined without a value #78179

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

kkwli
Copy link
Collaborator

@kkwli kkwli commented Jan 15, 2024

The _POSIX_SOURCE macro is defined without a value on AIX.

@kkwli kkwli self-assigned this Jan 15, 2024
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Jan 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 15, 2024

@llvm/pr-subscribers-flang-runtime

Author: Kelvin Li (kkwli)

Changes

The _POSIX_SOURCE macro is defined without a value on AIX.


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

2 Files Affected:

  • (modified) flang/runtime/extensions.cpp (+1-1)
  • (modified) flang/unittests/Runtime/CommandTest.cpp (+1-1)
diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
index 352da8f11d9d565..158998321b06662 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang/runtime/extensions.cpp
@@ -24,7 +24,7 @@ inline void CtimeBuffer(char *buffer, size_t bufsize, const time_t cur_time,
   RUNTIME_CHECK(terminator, error == 0);
 }
 #elif _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || \
-    _POSIX_SOURCE
+    defined(_POSIX_SOURCE)
 inline void CtimeBuffer(char *buffer, size_t bufsize, const time_t cur_time,
     Fortran::runtime::Terminator terminator) {
   const char *res{ctime_r(&cur_time, buffer)};
diff --git a/flang/unittests/Runtime/CommandTest.cpp b/flang/unittests/Runtime/CommandTest.cpp
index a0f14c519412a41..dfb4f2cd8bd9968 100644
--- a/flang/unittests/Runtime/CommandTest.cpp
+++ b/flang/unittests/Runtime/CommandTest.cpp
@@ -233,7 +233,7 @@ class NoArgv : public CommandFixture {
 };
 
 #if _WIN32 || _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || \
-    _SVID_SOURCE || _POSIX_SOURCE
+    _SVID_SOURCE || defined(_POSIX_SOURCE)
 TEST_F(NoArgv, FdateGetDate) {
   char input[]{"24LengthCharIsJustRight"};
   const std::size_t charLen = sizeof(input);

Copy link
Contributor

@yi-wu-arm yi-wu-arm left a comment

Choose a reason for hiding this comment

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

Don't know much about AIX but a define(_POSIX_SOURCE) would guarantee that it will work when define with and without a value, with the exception of 0.
I assume that there are no cases where it is defined as 0? Normally it should follow the yyyymm format like 200809L.

Copy link
Contributor

@klausler klausler left a comment

Choose a reason for hiding this comment

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

The old-school idiom for this would be (_POSIX_SOURCE+0).

You don't need the parentheses with defined.

Copy link
Contributor

@xingxue-ibm xingxue-ibm left a comment

Choose a reason for hiding this comment

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

LGTM.

@kkwli kkwli merged commit 8b6b882 into llvm:main Jan 15, 2024
5 of 6 checks passed
@kkwli kkwli deleted the posix_source-macro branch January 15, 2024 21:54
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
The `_POSIX_SOURCE` macro is defined without a value on AIX. Change the check to `defined(_POSIX_SOURCE)`.
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

5 participants