Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Darwin / asan-symbolize-templated-cxx.cpp
blob3d726a32b7eaa50f98a04500c1fa34def5ef4a4e
1 // UNSUPPORTED: ios
2 // RUN: %clangxx_asan -O0 -g %s -o %t.executable
3 // RUN: %env_asan_opts="symbolize=0" not %run %t.executable > %t_no_module_map.log 2>&1
4 // RUN: %asan_symbolize --force-system-symbolizer < %t_no_module_map.log 2>&1 | FileCheck %s
5 #include <cassert>
6 #include <cstdio>
7 #include <cstdlib>
8 #include <functional>
10 // This test is deliberately convoluted so that there is a function call
11 // in the stack trace that contains nested parentheses.
13 template <class CallBackTy>
14 class IntWrapper {
15 int value_;
16 std::function<CallBackTy> callback_;
18 public:
19 IntWrapper(int value, std::function<CallBackTy> callback) : value_(value), callback_(callback) {}
20 int &operator=(const int &new_value) {
21 value_ = new_value;
22 callback_(value_);
26 using IntW = IntWrapper<void(int)>;
27 IntW *a;
29 template <class T>
30 void writeToA(T new_value) {
31 // CHECK: heap-use-after-free
32 // NOTE: atos seems to emit the `void` return type here for some reason.
33 // CHECK: #{{[0-9]+}} 0x{{.+}} in {{(void +)?}}writeToA<IntWrapper<void{{ *}}(int)>{{ *}}>(IntWrapper<void{{ *}}(int)>) asan-symbolize-templated-cxx.cpp:[[@LINE+1]]
34 *a = new_value;
37 extern "C" void callback(int new_value) {
38 printf("new value is %d\n", new_value);
41 template <class T, class V>
42 struct Foo {
43 std::function<T> call;
44 Foo(std::function<T> c) : call(c) {}
45 void doCall(V new_value) {
46 // CHECK: #{{[0-9]+}} 0x{{.+}} in Foo<void (IntWrapper<void{{ *}}(int)>),{{ *}}IntWrapper<void{{ *}}(int)>{{ *}}>::doCall(IntWrapper<void{{ *}}(int)>) asan-symbolize-templated-cxx.cpp:[[@LINE+1]]
47 call(new_value);
51 int main() {
52 a = new IntW(0, callback);
53 assert(a);
54 // Foo<void(IntWrapper<void(int)>)>
55 // This type is deliberately convoluted so that the demangled type contains nested parentheses.
56 // In particular trying to match parentheses using a least-greedy regex approach will fail.
57 Foo<void(IntW), IntW> foo(writeToA<IntW>);
58 delete a;
59 // CHECK: #{{[0-9]+}} 0x{{.+}} in main asan-symbolize-templated-cxx.cpp:[[@LINE+1]]
60 foo.doCall(IntW(5, callback)); // BOOM
61 return 0;