16a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t 26a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll 36a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: not %run %t %t.dll 2>&1 | FileCheck %s 46a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines 56a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// Test that it works correctly even with ICF enabled. 66a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF 72d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: not %run %t %t.dll 2>&1 | FileCheck %s 82d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 92d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include <stdio.h> 102d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include <string.h> 112d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 122d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesextern "C" __declspec(dllexport) 132d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesint test_function() { 142d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines char buff1[6] = "Hello", buff2[5]; 152d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 166a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines memcpy(buff2, buff1, 5); 172d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines if (buff1[2] != buff2[2]) 182d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines return 2; 192d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines printf("Initial test OK\n"); 202d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines fflush(0); 212d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: Initial test OK 222d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 236a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines memcpy(buff2, buff1, 6); 242d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 252d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: WRITE of size 6 at [[ADDR]] thread T0 2686277eb844c4983c81de62d7c050e92fe7155788Stephen Hines// CHECK-NEXT: __asan_{{.*}}memcpy 276a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.cc:[[@LINE-4]] 282d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame 292d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.cc 302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable 316a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines return 0; 322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines} 33