1// Make sure everything works even if the main module doesn't have any stack
2// variables, thus doesn't explicitly reference any symbol exported by the
3// runtime thunk.
4//
5// RUN: %clang_cl_asan %LD %Od -DDLL1 %s %Fe%t1.dll \
6// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t1.lib %}
7// RUN: %clang_cl_asan %LD %Od -DDLL2 %s %Fe%t2.dll \
8// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t2.lib %}
9// RUN: %clang_cl_asan %Od -DEXE %s %t1.lib %t2.lib %Fe%t
10// RUN: not %run %t 2>&1 | FileCheck %s
11
12#include <malloc.h>
13#include <string.h>
14
15extern "C" {
16#if defined(EXE)
17__declspec(dllimport) void foo1();
18__declspec(dllimport) void foo2();
19
20int main() {
21 foo1();
22 foo2();
23}
24#elif defined(DLL1)
25__declspec(dllexport) void foo1() {}
26#elif defined(DLL2)
27__attribute__((noinline))
28static void NullDeref(int *ptr) {
29 // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
30 // CHECK: {{0x0*000.. .*pc 0x.*}}
31 ptr[10]++; // BOOM
32}
33
34__declspec(dllexport) void foo2() {
35 NullDeref((int*)0);
36 // CHECK: {{ #1 0x.* in foo2.*null_deref_multiple_dlls.cpp:}}[[@LINE-1]]
37 // CHECK: AddressSanitizer can not provide additional info.
38}
39#else
40# error oops!
41#endif
42}
43

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