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 "../defines.h"
13#include <malloc.h>
14#include <string.h>
15
16#if defined(EXE)
17extern "C" {
18__declspec(dllimport) void foo1();
19__declspec(dllimport) void foo2();
20}
21
22int main() {
23 foo1();
24 foo2();
25}
26#elif defined(DLL1)
27extern "C" {
28__declspec(dllexport) void foo1() {}
29}
30#elif defined(DLL2)
31extern "C" {
32ATTRIBUTE_NOINLINE
33static void NullDeref(int *ptr) {
34 // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
35 // CHECK: {{0x0*000.. .*pc 0x.*}}
36 ptr[10]++; // BOOM
37}
38
39__declspec(dllexport) void foo2() {
40 NullDeref((int *)0);
41 // CHECK: {{ #1 0x.* in foo2.*null_deref_multiple_dlls.cpp:}}[[@LINE-1]]
42 // CHECK: AddressSanitizer can not provide additional info.
43}
44}
45#else
46# error oops!
47#endif
48

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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