Skip to content

[libc++] Disables -Wweak-vtables diagnostics. #85577

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

Conversation

mordante
Copy link
Member

This is a preparation to use Clang HEAD in the CI.

@mordante mordante requested a review from a team as a code owner March 17, 2024 18:01
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 17, 2024

@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)

Changes

This is a preparation to use Clang HEAD in the CI.


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

1 Files Affected:

  • (modified) libcxx/include/__expected/bad_expected_access.h (+3)
diff --git a/libcxx/include/__expected/bad_expected_access.h b/libcxx/include/__expected/bad_expected_access.h
index 27f01d9350eea6..32547eba657633 100644
--- a/libcxx/include/__expected/bad_expected_access.h
+++ b/libcxx/include/__expected/bad_expected_access.h
@@ -27,6 +27,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template <class _Err>
 class bad_expected_access;
 
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables")
 template <>
 class bad_expected_access<void> : public exception {
 protected:
@@ -58,6 +60,7 @@ class bad_expected_access : public bad_expected_access<void> {
 private:
   _Err __unex_;
 };
+_LIBCPP_DIAGNOSTIC_POP
 
 _LIBCPP_END_NAMESPACE_STD
 

@@ -27,6 +27,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Err>
class bad_expected_access;

_LIBCPP_DIAGNOSTIC_PUSH
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wweak-vtables")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment why we disabled -Wweak-vtables here. We shouldn't just disable it because it happens to be diagnosed. We generally try to avoid weak vtables. FWIW I don't think we should disable it here either. We should instead provide a strong definition in the dylib if it's available on the target.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could. Do you think that would that be worth an ABI break?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we have to make it an ABI break. The weak symbols have, as the name suggests, weak linkage. So we can simply provide a strong definition in the dylib and only enable the generation of weak symbols on platforms which don't have them in the dylib yet. Similar to how we conditionally provide additional instantiations of iostream types.

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK We only use weak symbols for the replaceable functions and some debug functions. Not for other functions. I'm not sure whether we want do that. It would allow users to provide strong definitions of destructors they should not provide.

I can't find the example you mean, do you mean the templates guarded by _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK We only use weak symbols for the replaceable functions and some debug functions. Not for other functions. I'm not sure whether we want do that. It would allow users to provide strong definitions of destructors they should not provide.

inline symbols have weak linkage, we don't have to give that explicitly. You can see that in https://godbolt.org/z/a3P4P7qhE. The .weak test() gives test() weak linkage, and explicitly giving it weak linkage doesn't make any difference.

I can't find the example you mean, do you mean the templates guarded by _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 ?

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is only a difference for special member functions, since there are multiple sometimes. I don't know why clang decides to call the complete object destructor instead of the base object destructor when adding [[gnu::weak]] (maybe because it's considered replaceable with [[gnu::weak]]), but I don't think that's relevant. The fact that they are weak symbols without [[gnu::weak]] doesn't change.

What exactly did you try to add a definition to the dylib?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the header I removed _LIBCPP_HIDE_FROM_ABI_VIRTUAL and changed = default to {}, I also tried with _LIBCPP_OVERRIDABLE_FUNC_VIS and _LIBCPP_WEAK in the dylib I tried with and without _LIBCPP_WEAK. And all permutations of this; but clang dislikes the re-declaration.

Copy link
Member Author

Choose a reason for hiding this comment

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

@philnik777 friendly ping. I really like to move this patch forward since it blocks testing with Clang 19 in the CI.

Copy link
Member

Choose a reason for hiding this comment

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

@mordante Is Clang trunk complaining about the vtable of bad_expected_access<void> only, or about the one for the base template as well? Cause for the base template we can't do anything, but we could indeed do what @philnik777 said for the <void> specialization. We were basically "lazy" when we introduced bad_expected_access and decided not to put it in the dylib, but we could have.

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked and only disabling it for the void specialization works. However I tried to use _LIBCPP_WEAK with that specialization and that resulted in compilation errors. If you or @philnik777 know directly how to solve this feel free to commit patches to this review to solve it.

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

As the comment says. (Why TF is GitHub preventing me from requesting changes without a comment?)

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.

I am fine with this change as-is. It unblocks a Clang migration and it is consistent with what we do for bad_function_call. We should investigate how we can use availability instead for both bad_function_call and bad_expected_access, but that can (and should) be done in a separate patch cause it's non-trivial from an ABI standpoint.

@philnik777
Copy link
Contributor

I'd still like a comment why we disable it or a TODO that it shouldn't be the case.

@ldionne
Copy link
Member

ldionne commented Apr 2, 2024

I'd still like a comment why we disable it or a TODO that it shouldn't be the case.

Is this enough? #87390

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

I'd still like a comment why we disable it or a TODO that it shouldn't be the case.

Is this enough? #87390

Sure.

This is a preparation to use Clang HEAD in the CI.
@mordante mordante force-pushed the review/disabled_weak_vtable_diagnostics branch from 0d0f026 to d4e05fd Compare April 3, 2024 15:35
@mordante mordante merged commit a77d3d9 into llvm:main Apr 3, 2024
6 of 9 checks passed
@mordante mordante deleted the review/disabled_weak_vtable_diagnostics branch April 3, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants