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

[libc++] Fix the signatures of std::rethrow_if_nested #91365

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

frederick-vs-ja
Copy link
Contributor

Fixes #54470.

See [global.functions]/2:

A call to a non-member function signature described in [support] through [thread] and [depr] shall behave as if the implementation declared no additional non-member function signatures.

and [global.functions]/3:

An implementation shall not declare a non-member function signature with additional default arguments.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner May 7, 2024 17:44
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 7, 2024
@llvmbot
Copy link
Member

llvmbot commented May 7, 2024

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

Fixes #54470.

See [[global.functions]/2](https://eel.is/c++draft/global.functions#2):
> A call to a non-member function signature described in [support] through [thread] and [depr] shall behave as if the implementation declared no additional non-member function signatures.

and [[global.functions]/3](https://eel.is/c++draft/global.functions#3):
> An implementation shall not declare a non-member function signature with additional default arguments.


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

2 Files Affected:

  • (modified) libcxx/include/__exception/nested_exception.h (+4-6)
  • (modified) libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp (+27)
diff --git a/libcxx/include/__exception/nested_exception.h b/libcxx/include/__exception/nested_exception.h
index 1bf2df939258a..feb489f87f62f 100644
--- a/libcxx/include/__exception/nested_exception.h
+++ b/libcxx/include/__exception/nested_exception.h
@@ -84,17 +84,15 @@ struct __can_dynamic_cast
     : _BoolConstant< is_polymorphic<_From>::value &&
                      (!is_base_of<_To, _From>::value || is_convertible<const _From*, const _To*>::value)> {};
 
-template <class _Ep>
-inline _LIBCPP_HIDE_FROM_ABI void
-rethrow_if_nested(const _Ep& __e, __enable_if_t< __can_dynamic_cast<_Ep, nested_exception>::value>* = 0) {
+template <class _Ep, __enable_if_t< __can_dynamic_cast<_Ep, nested_exception>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep& __e) {
   const nested_exception* __nep = dynamic_cast<const nested_exception*>(std::addressof(__e));
   if (__nep)
     __nep->rethrow_nested();
 }
 
-template <class _Ep>
-inline _LIBCPP_HIDE_FROM_ABI void
-rethrow_if_nested(const _Ep&, __enable_if_t<!__can_dynamic_cast<_Ep, nested_exception>::value>* = 0) {}
+template <class _Ep, __enable_if_t<!__can_dynamic_cast<_Ep, nested_exception>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep&) {}
 
 } // namespace std
 
diff --git a/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp b/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
index 39bf62b8193bb..30ce86f5277b0 100644
--- a/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
+++ b/libcxx/test/std/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
@@ -18,8 +18,10 @@
 // template <class E> void rethrow_if_nested(const E& e);
 
 #include <exception>
+#include <cstddef>
 #include <cstdlib>
 #include <cassert>
+#include <utility>
 
 #include "test_macros.h"
 
@@ -58,6 +60,31 @@ class E1 : public std::nested_exception {};
 class E2 : public std::nested_exception {};
 class E : public E1, public E2 {};
 
+#if TEST_STD_VER >= 11
+template <class, class...>
+struct can_rethrow_if_nested_impl {
+  static constexpr bool value = false;
+};
+
+template <class... Args>
+struct can_rethrow_if_nested_impl<decltype((void)std::rethrow_if_nested(std::declval<Args>()...)), Args...> {
+  static constexpr bool value = true;
+};
+
+template <class... Args>
+struct can_rethrow_if_nested : can_rethrow_if_nested_impl<void, Args...> {};
+
+static_assert(!can_rethrow_if_nested<>::value, "");
+static_assert(can_rethrow_if_nested<A>::value, "");
+static_assert(can_rethrow_if_nested<const A&>::value, "");
+static_assert(can_rethrow_if_nested<B>::value, "");
+static_assert(can_rethrow_if_nested<const B&>::value, "");
+static_assert(!can_rethrow_if_nested<A, int*>::value, "");
+static_assert(!can_rethrow_if_nested<B, int*>::value, "");
+static_assert(!can_rethrow_if_nested<A, std::nullptr_t>::value, "");
+static_assert(!can_rethrow_if_nested<B, std::nullptr_t>::value, "");
+#endif
+
 int main(int, char**)
 {
     {

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.

Thanks, LGTM if CI is green!

@frederick-vs-ja frederick-vs-ja force-pushed the rethrow_if_nested-sig-fix branch from 803955c to eb816ff Compare May 11, 2024 08:07
@frederick-vs-ja frederick-vs-ja force-pushed the rethrow_if_nested-sig-fix branch from eb816ff to f573934 Compare May 29, 2024 10:04
@frederick-vs-ja frederick-vs-ja force-pushed the rethrow_if_nested-sig-fix branch from f573934 to bb1e930 Compare July 1, 2024 06:55
@frederick-vs-ja
Copy link
Contributor Author

@ldionne CI looks fine now. Ping.

@ldionne ldionne merged commit 0865b78 into llvm:main Jul 3, 2024
53 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 3, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-aarch64-linux running on sanitizer-buildbot8 while building libcxx at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/821

Here is the relevant piece of the build log for the reference:

Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
+ grep -Ev '^#|^$' /b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
+ sort -u
+ diff -u expected.new undefined.new
+ grep -E '^\+[^+]'
+pthread_cond_destroy U
+pthread_cond_signal U
+ echo 'Failed: unexpected symbols'
Failed: unexpected symbols
+ exit 1
[1921/1979] Building CXX object compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.aarch64.dir/asan_interceptors.cpp.o
FAILED: compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o 
cd /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64 && FLAGS=-march=armv8-a CLANG=/b/sanitizer-aarch64-linux/build/build_symbolizer/./bin/clang /b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o
ninja: build stopped: subcommand failed.
FAILED: runtimes/runtimes-stamps/runtimes-build /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-stamps/runtimes-build 
cd /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.
+ touch build_symbolizer/delete_next_time
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
@@@STEP_FAILURE@@@
@@@BUILD_STEP test compiler-rt symbolizer@@@
+ local build_dir=build_symbolizer
+ echo '@@@BUILD_STEP test compiler-rt symbolizer@@@'
+ ninja -C build_symbolizer check-compiler-rt
ninja: Entering directory `build_symbolizer'
[0/5] Performing build step for 'builtins'
ninja: no work to do.
[1/5] No install step for 'builtins'
[3/5] Completed 'builtins'
[3/5] Performing configure step for 'runtimes'
CMake Deprecation Warning at /b/sanitizer-aarch64-linux/build/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0114 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:6 (include)
Step 10 (build compiler-rt symbolizer) failure: build compiler-rt symbolizer (failure)
...
+ grep -Ev '^#|^$' /b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
+ sort -u
+ diff -u expected.new undefined.new
+ grep -E '^\+[^+]'
+pthread_cond_destroy U
+pthread_cond_signal U
+ echo 'Failed: unexpected symbols'
Failed: unexpected symbols
+ exit 1
[1921/1979] Building CXX object compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.aarch64.dir/asan_interceptors.cpp.o
FAILED: compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o 
cd /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64 && FLAGS=-march=armv8-a CLANG=/b/sanitizer-aarch64-linux/build/build_symbolizer/./bin/clang /b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o
ninja: build stopped: subcommand failed.
FAILED: runtimes/runtimes-stamps/runtimes-build /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-stamps/runtimes-build 
cd /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.
+ touch build_symbolizer/delete_next_time
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
Step 11 (test compiler-rt symbolizer) failure: test compiler-rt symbolizer (failure)
...
+ grep -Ev '^#|^$' /b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt
+ sort -u
+ diff -u expected.new undefined.new
+ grep -E '^\+[^+]'
+pthread_cond_destroy U
+pthread_cond_signal U
+ echo 'Failed: unexpected symbols'
+ exit 1
Failed: unexpected symbols
[42/201] Generating ScudoUnitTest-aarch64-Test
FAILED: compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o 
cd /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64 && FLAGS=-march=armv8-a CLANG=/b/sanitizer-aarch64-linux/build/build_symbolizer/./bin/clang /b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/symbolizer/RTSanitizerCommonSymbolizerInternal.aarch64.o
ninja: build stopped: subcommand failed.
FAILED: runtimes/CMakeFiles/check-compiler-rt /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/CMakeFiles/check-compiler-rt 
cd /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins && /usr/bin/cmake --build /b/sanitizer-aarch64-linux/build/build_symbolizer/runtimes/runtimes-bins/ --target check-compiler-rt --config Release
ninja: build stopped: subcommand failed.
+ build_failure
+ echo
+ echo 'How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild'
+ echo
+ sleep 5

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
+ echo @@@STEP_FAILURE@@@
+ [[ '' == \1 ]]
+ [[ ! -v BUILDBOT_BUILDERNAME ]]
+ LIT_FILTER_OUT='(AddressSanitizer|asan|ubsan)'
+ build_and_test debug -DCOMPILER_RT_DEBUG=ON
+ build debug -DCOMPILER_RT_DEBUG=ON
+ local build_dir=build_debug
+ echo '@@@BUILD_STEP build compiler-rt debug@@@'
+ [[ ! -f build_debug/delete_next_time ]]
+ mkdir -p build_debug

@ldionne
Copy link
Member

ldionne commented Jul 3, 2024

First time I see this bot commenting. I looked at the failure and this looks like noise. I'm not too happy that we have a bot spamming PRs with post-review CI results now.

lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
Fixes llvm#54470.

See https://eel.is/c++draft/global.functions#2:
    > A call to a non-member function signature described in [support]
    > through [thread] and [depr] shall behave as if the implementation
    > declared no additional non-member function signatures.

and https://eel.is/c++draft/global.functions#3:
    > An implementation shall not declare a non-member function signature
    > with additional default arguments.
@frederick-vs-ja frederick-vs-ja deleted the rethrow_if_nested-sig-fix branch July 4, 2024 02:27
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
Fixes llvm#54470.

See https://eel.is/c++draft/global.functions#2:
    > A call to a non-member function signature described in [support]
    > through [thread] and [depr] shall behave as if the implementation
    > declared no additional non-member function signatures.

and https://eel.is/c++draft/global.functions#3:
    > An implementation shall not declare a non-member function signature
    > with additional default arguments.
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.

libc++: rethrow_if_nested has wrong signatures
4 participants