13c8e31e1SArthur O'Dwyer //===----------------------------------------------------------------------===//
23c8e31e1SArthur O'Dwyer //
33c8e31e1SArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43c8e31e1SArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
53c8e31e1SArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63c8e31e1SArthur O'Dwyer //
73c8e31e1SArthur O'Dwyer //===----------------------------------------------------------------------===//
83c8e31e1SArthur O'Dwyer
9434dc0a5SKonstantin Varlamov // Address Sanitizer doesn't instrument weak symbols on Linux. When a key
10434dc0a5SKonstantin Varlamov // function is defined for bad_function_call's vtable, its typeinfo and vtable
11434dc0a5SKonstantin Varlamov // will be defined as strong symbols in the library and weak symbols in other
12434dc0a5SKonstantin Varlamov // translation units. Only the strong symbol will be instrumented, increasing
13434dc0a5SKonstantin Varlamov // its size (due to the redzone) and leading to a serious ODR violation
14434dc0a5SKonstantin Varlamov // resulting in a crash.
15434dc0a5SKonstantin Varlamov // Some relevant bugs:
16434dc0a5SKonstantin Varlamov // https://github.com/google/sanitizers/issues/1017
17434dc0a5SKonstantin Varlamov // https://github.com/google/sanitizers/issues/619
18434dc0a5SKonstantin Varlamov // https://github.com/google/sanitizers/issues/398
19434dc0a5SKonstantin Varlamov // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68016
20434dc0a5SKonstantin Varlamov // UNSUPPORTED: c++03, asan
213c8e31e1SArthur O'Dwyer
223c8e31e1SArthur O'Dwyer // <functional>
233c8e31e1SArthur O'Dwyer
243c8e31e1SArthur O'Dwyer #include <functional>
253c8e31e1SArthur O'Dwyer
263c8e31e1SArthur O'Dwyer #include "test_macros.h"
273c8e31e1SArthur O'Dwyer
283c8e31e1SArthur O'Dwyer struct Incomplete;
293c8e31e1SArthur O'Dwyer template<class T> struct Holder { T t; };
30*e24ddb60SLouis Dionne
313c8e31e1SArthur O'Dwyer typedef Holder<Incomplete> *Ptr;
323c8e31e1SArthur O'Dwyer
33*e24ddb60SLouis Dionne template<class T>
34*e24ddb60SLouis Dionne struct Callable {
operator ()Callable35*e24ddb60SLouis Dionne void operator()() const { }
36*e24ddb60SLouis Dionne };
37*e24ddb60SLouis Dionne
no_args()383c8e31e1SArthur O'Dwyer Ptr no_args() { return nullptr; }
one_arg(Ptr p)393c8e31e1SArthur O'Dwyer Ptr one_arg(Ptr p) { return p; }
two_args(Ptr p,Ptr)403c8e31e1SArthur O'Dwyer Ptr two_args(Ptr p, Ptr) { return p; }
three_args(Ptr p,Ptr,Ptr)413c8e31e1SArthur O'Dwyer Ptr three_args(Ptr p, Ptr, Ptr) { return p; }
four_args(Ptr p,Ptr,Ptr,Ptr)423c8e31e1SArthur O'Dwyer Ptr four_args(Ptr p, Ptr, Ptr, Ptr) { return p; }
433c8e31e1SArthur O'Dwyer
one_arg_void(Ptr)443c8e31e1SArthur O'Dwyer void one_arg_void(Ptr) { }
453c8e31e1SArthur O'Dwyer
main(int,char **)46*e24ddb60SLouis Dionne int main(int, char**) {
473c8e31e1SArthur O'Dwyer Ptr x = nullptr;
483c8e31e1SArthur O'Dwyer std::function<Ptr()> f(no_args); f();
493c8e31e1SArthur O'Dwyer std::function<Ptr(Ptr)> g(one_arg); g(x);
503c8e31e1SArthur O'Dwyer std::function<void(Ptr)> h(one_arg_void); h(x);
51*e24ddb60SLouis Dionne std::function<void()> i(Callable<Holder<Incomplete>>{});
523c8e31e1SArthur O'Dwyer return 0;
533c8e31e1SArthur O'Dwyer }
54