54 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// Address Sanitizer doesn't instrument weak symbols on Linux. When a key10// function is defined for bad_function_call's vtable, its typeinfo and vtable11// will be defined as strong symbols in the library and weak symbols in other12// translation units. Only the strong symbol will be instrumented, increasing13// its size (due to the redzone) and leading to a serious ODR violation14// resulting in a crash.15// Some relevant bugs:16// https://github.com/google/sanitizers/issues/101717// https://github.com/google/sanitizers/issues/61918// https://github.com/google/sanitizers/issues/39819// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6801620// UNSUPPORTED: c++03, asan21 22// <functional>23 24#include <functional>25 26#include "test_macros.h"27 28struct Incomplete;29template<class T> struct Holder { T t; };30 31typedef Holder<Incomplete> *Ptr;32 33template<class T>34struct Callable {35 void operator()() const { }36};37 38Ptr no_args() { return nullptr; }39Ptr one_arg(Ptr p) { return p; }40Ptr two_args(Ptr p, Ptr) { return p; }41Ptr three_args(Ptr p, Ptr, Ptr) { return p; }42Ptr four_args(Ptr p, Ptr, Ptr, Ptr) { return p; }43 44void one_arg_void(Ptr) { }45 46int main(int, char**) {47 Ptr x = nullptr;48 std::function<Ptr()> f(no_args); f();49 std::function<Ptr(Ptr)> g(one_arg); g(x);50 std::function<void(Ptr)> h(one_arg_void); h(x);51 std::function<void()> i(Callable<Holder<Incomplete>>{});52 return 0;53}54