Skip to content

flang: Fix build with latest libc++ #127362

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

Merged
merged 5 commits into from
Feb 19, 2025
Merged

Conversation

tstellar
Copy link
Collaborator

I think this first stopped working with
9548366. This patch fixes the following error:

/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11: error: '__libcpp_verbose_abort' is missing exception specification 'noexcept'
153 | void std::__libcpp_verbose_abort(char const format, ...) {
| ^
| noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous declaration is here
30 | printf, 1, 2) void __libcpp_verbose_abort(const char
__format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
| ^
1 error generated.

I think this first stopped working with
9548366.  This patch fixes the
following error:

/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11: error: '__libcpp_verbose_abort' is missing exception specification 'noexcept'
   153 | void std::__libcpp_verbose_abort(char const *format, ...) {
       |           ^
       |                                                           noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous declaration is here
    30 |     __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
       |                            ^
1 error generated.
@tstellar tstellar added this to the LLVM 20.X Release milestone Feb 16, 2025
@tstellar tstellar requested review from mmuetzel and a team February 16, 2025 01:34
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Feb 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 16, 2025

@llvm/pr-subscribers-flang-runtime

Author: Tom Stellard (tstellar)

Changes

I think this first stopped working with
9548366. This patch fixes the following error:

/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11: error: '__libcpp_verbose_abort' is missing exception specification 'noexcept'
153 | void std::__libcpp_verbose_abort(char const format, ...) {
| ^
| noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous declaration is here
30 | printf, 1, 2) void __libcpp_verbose_abort(const char
__format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
| ^
1 error generated.


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

1 Files Affected:

  • (modified) flang/runtime/io-api-minimal.cpp (+6-1)
diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp
index 68768427be0c2..e53089e02d93d 100644
--- a/flang/runtime/io-api-minimal.cpp
+++ b/flang/runtime/io-api-minimal.cpp
@@ -150,7 +150,12 @@ bool IODEF(OutputLogical)(Cookie cookie, bool truth) {
 // Provide own definition for `std::__libcpp_verbose_abort` to avoid dependency
 // on the version provided by libc++.
 
-void std::__libcpp_verbose_abort(char const *format, ...) {
+#if !defined(_LIBCPP_VERBOSE_ABORT_NOEXCEPT)
+  #define _LIBCPP_VERBOSE_ABORT_NOEXCEPT
+#endif
+
+
+void std::__libcpp_verbose_abort(char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT {
   va_list list;
   va_start(list, format);
   std::vfprintf(stderr, format, list);

Copy link

github-actions bot commented Feb 16, 2025

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

@mmuetzel
Copy link
Contributor

I can't comment on the general question whether it is supported by libc++ to use headers from the STL without linking to the library.
But the proposed change looks like a valid fix for the existing work-around to me. 👍

@mmuetzel
Copy link
Contributor

mmuetzel commented Feb 17, 2025

Fwiw, a similar issue was previously reported in #113059 and fixed(?) with #113310.

Comment on lines 153 to 158
#if !defined(_LIBCPP_VERBOSE_ABORT_NOEXCEPT)
#define _LIBCPP_VERBOSE_ABORT_NOEXCEPT
#endif

void std::__libcpp_verbose_abort(
char const *format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT {
Copy link
Member

Choose a reason for hiding this comment

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

The right way of fixing this would be:

void std::__libcpp_verbose_abort(char const *format, ...)
    noexcept(noexcept(std::__libcpp_verbose_abort("")))
{
  // ...
}

This allows unconditionally using the right noexcept-ness based on how the base function has been declared.

About the more general question of whether libc++ supports being used header-only (without linking against the dylib), the answer is no, but some stuff will still happen to work if you do that. That's a brittle setup though, for example I expect that you would encounter a linker error if you tried using std::shared_ptr or std::sort(int*, int*) anywhere since those are in the dylib. Is there a reason why you don't link against the libc++ built library?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why you don't link against the libc++ built library?

That is a very good question that I was pondering myself repeatedly.
I hope it is ok to ask @sscalpone for clarification.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ldionne I've implemented your suggested fix.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

LGTM.

I think Flang should figure out why they're not linking against libc++ since that will break other stuff in the future. But in the interest of fixing the current state of trunk, this patch works and doesn't make anything worse than it already is.

@tstellar tstellar merged commit 2b340c1 into llvm:main Feb 19, 2025
6 checks passed
@tstellar
Copy link
Collaborator Author

/cherry-pick 2b340c1

@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

/pull-request #127805

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 20, 2025
I think this first stopped working with
9548366. This patch fixes the following
error:

/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11:
error: '__libcpp_verbose_abort' is missing exception specification
'noexcept'
   153 | void std::__libcpp_verbose_abort(char const *format, ...) {
       |           ^
| noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous
declaration is here
30 | __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format,
...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
       |                            ^
1 error generated.

(cherry picked from commit 2b340c1)
@Meinersbur
Copy link
Member

I had already tried to fix this, but had to revert in 81c85ea due to a buildbot failure. Thanks for taking care.

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
Development

Successfully merging this pull request may close these issues.

5 participants