brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 6036f0f Raw
52 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// template<CopyConstructible Fn, CopyConstructible... Types>25//   unspecified bind(Fn, Types...);26// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>27//   unspecified bind(Fn, Types...);28 29// https://llvm.org/PR1638530 31#include <functional>32#include <cmath>33#include <cassert>34 35#include "test_macros.h"36 37float _pow(float a, float b)38{39    return std::pow(a, b);40}41 42int main(int, char**)43{44    std::function<float(float, float)> fnc = _pow;45    auto task = std::bind(fnc, 2.f, 4.f);46    auto task2(task);47    assert(task() == 16);48    assert(task2() == 16);49 50  return 0;51}52