| 1 | // RUN: %clang_cl_asan %Od %s %Fe%t |
| 2 | // RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,%if target={{.*-windows-msvc.*}} %{MSVC%} %else %{MINGW%} |
| 3 | // |
| 4 | // This test makes sure ASan symbolizes stack traces the way they are typically |
| 5 | // symbolized on Windows. |
| 6 | #include <malloc.h> |
| 7 | |
| 8 | namespace foo { |
| 9 | // A template function in a namespace. |
| 10 | template<int x> |
| 11 | void bar(char *p) { |
| 12 | *p = x; |
| 13 | } |
| 14 | |
| 15 | // A regular function in a namespace. |
| 16 | void spam(char *p) { |
| 17 | bar<42>(p); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | // A multi-argument template with a bool template parameter. |
| 22 | template<typename T, bool U> |
| 23 | void baz(T t) { |
| 24 | if (U) |
| 25 | foo::spam(p: t); |
| 26 | } |
| 27 | |
| 28 | template<typename T> |
| 29 | struct A { |
| 30 | A(T v) { v_ = v; } |
| 31 | ~A(); |
| 32 | char *v_; |
| 33 | }; |
| 34 | |
| 35 | // A destructor of a template class. |
| 36 | template<> |
| 37 | A<char*>::~A() { |
| 38 | baz<char*, true>(t: v_); |
| 39 | } |
| 40 | |
| 41 | int main() { |
| 42 | char *buffer = (char*)malloc(size: 42); |
| 43 | free(ptr: buffer); |
| 44 | A<char*> a(buffer); |
| 45 | // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]] |
| 46 | // CHECK: foo::bar<42>{{.*}}demangled_names.cpp |
| 47 | // CHECK: foo::spam{{.*}}demangled_names.cpp |
| 48 | // MSVC: baz<char *,{{ *}}1>{{.*}}demangled_names.cpp |
| 49 | // MINGW: baz<char*, true>{{.*}}demangled_names.cpp |
| 50 | // MSVC: A<char *>::~A<char *>{{.*}}demangled_names.cpp |
| 51 | // MINGW: A<char*>::~A(){{.*}}demangled_names.cpp |
| 52 | } |
| 53 | |