50 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: stdlib=apple-libc++10 11// This test is dependent on the code generated by the compiler, and it doesn't12// work properly with older AppleClangs.13// UNSUPPORTED: apple-clang-1514 15// This test ensures that we retain a way to disable availability markup on Apple platforms16// in order to work around Clang bug https://llvm.org/PR134151.17//18// Once that bug has been fixed or once we've made changes to libc++'s use of availability19// that render that workaround unnecessary, the macro and this test can be removed.20//21// The test works by creating a final linked image that refers to a function marked with22// both an availability attribute and with _LIBCPP_HIDE_FROM_ABI. We then check that this23// generates a weak reference to the function -- without the bug, we'd expect a strong24// reference or no reference at all instead.25 26// First, test the test. Make sure that we do (incorrectly) produce a weak definition when we27// don't define _LIBCPP_DISABLE_AVAILABILITY. Otherwise, something may have changed in libc++28// and this test might not work anymore.29// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -shared -o %t.1.dylib30// RUN: nm -m %t.1.dylib | c++filt | grep value > %t.1.symbols31// RUN: grep weak %t.1.symbols32 33// Now, make sure that 'weak' goes away when we define _LIBCPP_DISABLE_AVAILABILITY.34// In fact, all references to the function might go away, so we just check that we don't emit35// any weak reference.36// RUN: %{cxx} %s %{flags} %{compile_flags} %{link_flags} -fvisibility=hidden -fvisibility-inlines-hidden -D_LIBCPP_DISABLE_AVAILABILITY -shared -o %t.2.dylib37// RUN: nm -m %t.2.dylib | c++filt | grep value > %t.2.symbols38// RUN: not grep weak %t.2.symbols39 40#include <version>41 42template <class T>43struct optional {44 T val_;45 _LIBCPP_HIDE_FROM_ABI _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE T value() const { return val_; }46};47 48using PMF = int (optional<int>::*)() const;49PMF f() { return &optional<int>::value; }50