blob: 15dce83ce18aac36a83ab5281d6573a2f19eaa8a [file] [log] [blame]
Kostya Serebryany712fc982016-06-07 01:20:26 +00001// RUN: %clang_scudo %s -o %t
2// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck %s
3// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t mallocdel 2>&1
4// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck %s
5// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t newfree 2>&1
6// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t memaligndel 2>&1 | FileCheck %s
7// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t memaligndel 2>&1
8
9// Tests that type mismatches between allocation and deallocation functions are
10// caught when the related option is set.
11
12#include <assert.h>
Kostya Kortchinsky8d6257b2017-02-03 20:49:42 +000013#include <malloc.h>
Kostya Serebryany712fc982016-06-07 01:20:26 +000014#include <stdlib.h>
15#include <string.h>
Kostya Serebryany712fc982016-06-07 01:20:26 +000016
17int main(int argc, char **argv)
18{
19 assert(argc == 2);
20 if (!strcmp(argv[1], "mallocdel")) {
21 int *p = (int *)malloc(16);
Kostya Kortchinsky8d6257b2017-02-03 20:49:42 +000022 assert(p);
Kostya Serebryany712fc982016-06-07 01:20:26 +000023 delete p;
24 }
25 if (!strcmp(argv[1], "newfree")) {
26 int *p = new int;
Kostya Kortchinsky8d6257b2017-02-03 20:49:42 +000027 assert(p);
Kostya Serebryany712fc982016-06-07 01:20:26 +000028 free((void *)p);
29 }
30 if (!strcmp(argv[1], "memaligndel")) {
Kostya Kortchinsky1148dc52016-11-30 17:32:20 +000031 int *p = (int *)memalign(16, 16);
Kostya Kortchinsky8d6257b2017-02-03 20:49:42 +000032 assert(p);
Kostya Serebryany712fc982016-06-07 01:20:26 +000033 delete p;
34 }
35 return 0;
36}
37
38// CHECK: ERROR: allocation type mismatch on address