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
8namespace foo {
9// A template function in a namespace.
10template<int x>
11void bar(char *p) {
12 *p = x;
13}
14
15// A regular function in a namespace.
16void spam(char *p) {
17 bar<42>(p);
18}
19}
20
21// A multi-argument template with a bool template parameter.
22template<typename T, bool U>
23void baz(T t) {
24 if (U)
25 foo::spam(p: t);
26}
27
28template<typename T>
29struct A {
30 A(T v) { v_ = v; }
31 ~A();
32 char *v_;
33};
34
35// A destructor of a template class.
36template<>
37A<char*>::~A() {
38 baz<char*, true>(t: v_);
39}
40
41int 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

source code of compiler-rt/test/asan/TestCases/Windows/demangled_names.cpp