blob: fdb68c0cdea57a5dd1a596effb7d507e71702a29 [file] [log] [blame]
Stephen Hines86277eb2015-03-23 12:06:32 -07001// RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08002
3// REQUIRES: stable-runtime
Stephen Hines86277eb2015-03-23 12:06:32 -07004
5#include <sanitizer/common_interface_defs.h>
6#include <stdio.h>
Stephen Hines86277eb2015-03-23 12:06:32 -07007
8volatile char *zero = 0;
9
10void Death() {
11 fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
12}
13// CHECK: DEATH CALLBACK EXECUTED
14
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080015char global;
Stephen Hines86277eb2015-03-23 12:06:32 -070016volatile char *sink;
17
Stephen Hines86277eb2015-03-23 12:06:32 -070018__attribute__((noinline))
19void MaybeInit(int *uninitialized) {
20 if (zero)
21 *uninitialized = 1;
22}
23
24__attribute__((noinline))
25void Leak() {
26 sink = new char[100]; // trigger lsan report.
27}
28
29int main(int argc, char **argv) {
30 int uninitialized;
31 __sanitizer_set_death_callback(Death);
32 MaybeInit(&uninitialized);
33 if (uninitialized) // trigger msan report.
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080034 global = 77;
35 sink = new char[100];
36 delete[] sink;
37 global = sink[0]; // use-after-free: trigger asan/tsan report.
Stephen Hines86277eb2015-03-23 12:06:32 -070038 Leak();
39 sink = 0;
40}