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

Fix C++ portability issue with using CMPLX #24211

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

bradcray
Copy link
Member

@bradcray bradcray commented Jan 18, 2024

Though compiling PR #24184 with a back-end C++ compiler worked on my laptop and [redacted], it caused problems with other C++ compilers, like g++ (SUSE Linux) 7.5.0 on [redacted] and some of our other nightly testing configurations.

At present, it's somewhat circumstantial that we compile this code with a C++ compiler at all: It only happens when compiling our qio re2 shim code, and that code doesn't rely on these tuple-to-complex conversion routines anyway. As a result, what I've done here is to beef up my #ifndef to skip over the new preferred path of code when we're compiling for C++ to be safe, and on the assumption that it doesn't really matter anyway (won't be called); and even if that changes in the future, the fallback paths from #24184 ought to work...

(As potentiall future work, we could also refactor our header files so that the re2 shim only gets definitions that it truly needs, which probably would involve forking some portions of chpltypes.h out of it and into another header. I started into this as part of #24184 before deciding it was overkill for that PR).

Though compiling PR chapel-lang#24184 with a back-end C++ compiler worked on my laptop
and chapcs11, it caused problems with other C++ compilers, like g++ (SUSE
Linux) 7.5.0 on [redacted] and some of our other nightly configurations.

At present, it's somewhat circumstantial that we compile this code with a C++
compiler: It only happens when compiling our qio re2 shim code, and that code
doesn't rely on these tuple-to-complex conversion routines anyway.  As a
result, what I've done here is to beef up my #ifndef to skip over the new
preferred path of code when we're compiling for C++ to be safe, and on the
assumption that it doesn't really matter anyway (won't be called); and even if
that changes in the future, the fallback paths from chapel-lang#24184 ought to work...

---
Signed-off-by: Brad Chamberlain <bradcray@users.noreply.github.com>
@bradcray bradcray merged commit 774462d into chapel-lang:main Jan 18, 2024
7 checks passed
@bradcray bradcray deleted the fix-cmplx-portability branch January 18, 2024 00:26
// test environments, so dodge it to be safe; Currently, we only compile
// this header using a C++ compiler when compiling our re2 stubs, which
// don't seem to use this routine anyway.
#if defined(CMPLX) && !defined(__cplusplus)
Copy link
Member

Choose a reason for hiding this comment

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

Did you intend to have this checking for CMPLXF ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, thank you. Opposite of usual: Remembered to update the comment, but not the code.

bradcray added a commit to bradcray/chapel that referenced this pull request Jan 19, 2024
---
Signed-off-by: Brad Chamberlain <bradcray@users.noreply.github.com>
bradcray added a commit that referenced this pull request Jan 19, 2024
[trivial mistake by me, caught by @mppf]
mppf added a commit that referenced this pull request Jan 25, 2024
Follow-up to PR #24127.

After #24127, the new `sqrtparams` test started to fail on Mac OS X
system. Upon investigating, I identified that the difference in behavior
from what the test expects is due to differences in how `std::sqrt` is
implemented for complex numbers in libc++ vs stdlibc++. Also, I noticed
that the issue is limited to the C++ implementation of the complex
square root.

This PR changes the implementation to use a C implementation of complex
square root since it appears to have more reliable precision. Note that
this C implementation required some workarounds for `CMPLX` not being
available on all systems (as with PR #24184 and #24211). In particular,
`CMPLX` does not seem to be available when using `clang` on Ubuntu
23.10, even though it is available with `gcc` on that system.

I filed an issue against libc++ about the problem, but in discussion
there it sounds like complex `sqrt` isn't required to have any
particular precision.
 * llvm/llvm-project#78738

Reviewed by @DanilaFe - thanks!

- [x] full comm=none testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants