Debian Codegraph @

libcxx/test/libcxx-03/vendor/apple/disable-availability.sh.cpp

raw
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // REQUIRES: stdlib=apple-libc++
10
11 // This test is dependent on the code generated by the compiler, and it doesn't
12 // work properly with older AppleClangs.
13 // UNSUPPORTED: apple-clang-15
14
15 // This test ensures that we retain a way to disable availability markup on Apple platforms
16 // 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 availability
19 // 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 with
22 // both an availability attribute and with _LIBCPP_HIDE_FROM_ABI. We then check that this
23 // generates a weak reference to the function -- without the bug, we'd expect a strong
24 // reference or no reference at all instead.
25
26 // First, test the test. Make sure that we do (incorrectly) produce a weak definition when we
27 // 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.dylib
30 // RUN: nm -m %t.1.dylib | c++filt | grep value > %t.1.symbols
31 // RUN: grep weak %t.1.symbols
32
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 emit
35 // 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.dylib
37 // RUN: nm -m %t.2.dylib | c++filt | grep value > %t.2.symbols
38 // RUN: not grep weak %t.2.symbols
39
40 #include <version>
41
42 template <class T>
43 struct optional {
44 T val_;
45 _LIBCPP_HIDE_FROM_ABI _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE T value() const { return val_; }
46 };
47
48 using PMF = int (optional<int>::*)() const;
49 PMF f() { return &optional<int>::value; }