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 // Address Sanitizer doesn't instrument weak symbols on Linux. When a key
10 // function is defined for bad_function_call's vtable, its typeinfo and vtable
11 // will be defined as strong symbols in the library and weak symbols in other
12 // translation units. Only the strong symbol will be instrumented, increasing
13 // its size (due to the redzone) and leading to a serious ODR violation
14 // resulting in a crash.
15 // Some relevant bugs:
16 // https://github.com/google/sanitizers/issues/1017
17 // https://github.com/google/sanitizers/issues/619
18 // https://github.com/google/sanitizers/issues/398
19 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68016
20 // UNSUPPORTED: c++03, asan
21 
22 // <functional>
23 
24 #include <functional>
25 
26 #include "test_macros.h"
27 
28 struct Incomplete;
29 template<class T> struct Holder { T t; };
30 typedef Holder<Incomplete> *Ptr;
31 
32 Ptr no_args() { return nullptr; }
33 Ptr one_arg(Ptr p) { return p; }
34 Ptr two_args(Ptr p, Ptr) { return p; }
35 Ptr three_args(Ptr p, Ptr, Ptr) { return p; }
36 Ptr four_args(Ptr p, Ptr, Ptr, Ptr) { return p; }
37 
38 void one_arg_void(Ptr) { }
39 
40 int main(int, char**)
41 {
42     Ptr x = nullptr;
43     std::function<Ptr()> f(no_args); f();
44     std::function<Ptr(Ptr)> g(one_arg); g(x);
45     std::function<void(Ptr)> h(one_arg_void); h(x);
46     return 0;
47 }
48