xref: /llvm-project/compiler-rt/test/lsan/TestCases/use_poisoned_asan.cpp (revision d08e5d4cc66ad8d3cb9342f263c35e40c0dd6215)
197ccf6b8SFangrui Song // ASan-poisoned memory should be ignored if use_poisoned is false.
297ccf6b8SFangrui Song // REQUIRES: asan
397ccf6b8SFangrui Song // RUN: %clangxx_lsan %s -o %t
4*d08e5d4cSClemens Wasser // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_poisoned=0" not %run %t 2>&1 | FileCheck %s
5*d08e5d4cSClemens Wasser // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_poisoned=1" %run %t 2>&1
697ccf6b8SFangrui Song 
797ccf6b8SFangrui Song #include <stdio.h>
897ccf6b8SFangrui Song #include <stdlib.h>
997ccf6b8SFangrui Song #include <sanitizer/asan_interface.h>
1097ccf6b8SFangrui Song #include <assert.h>
1197ccf6b8SFangrui Song #include "sanitizer_common/print_address.h"
1297ccf6b8SFangrui Song 
1397ccf6b8SFangrui Song void **p;
1497ccf6b8SFangrui Song 
main()1597ccf6b8SFangrui Song int main() {
1697ccf6b8SFangrui Song   p = new void *;
1797ccf6b8SFangrui Song   *p = malloc(1337);
1897ccf6b8SFangrui Song   print_address("Test alloc: ", 1, *p);
1997ccf6b8SFangrui Song   __asan_poison_memory_region(p, sizeof(*p));
2097ccf6b8SFangrui Song   return 0;
2197ccf6b8SFangrui Song }
2297ccf6b8SFangrui Song // CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
2397ccf6b8SFangrui Song // CHECK: LeakSanitizer: detected memory leaks
2497ccf6b8SFangrui Song // CHECK: [[ADDR]] (1337 bytes)
2597ccf6b8SFangrui Song // CHECK: SUMMARY: AddressSanitizer:
26