]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/msan/realloc-origin.cc
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / msan / realloc-origin.cc
1 // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && not %run %t >%t.out 2>&1
2 // RUN: FileCheck %s < %t.out
3 // RUN: %clangxx_msan -fsanitize-memory-track-origins -O2 %s -o %t && not %run %t >%t.out 2>&1
4 // RUN: FileCheck %s < %t.out
5
6 // This test relies on realloc from 100 to 101 being done in-place.
7
8 #include <stdlib.h>
9 int main(int argc, char **argv) {
10   char *p = (char *)malloc(100);
11   p = (char *)realloc(p, 101);
12   char x = p[100];
13   free(p);
14   return x;
15   // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
16   // CHECK: {{#0 0x.* in main .*realloc-origin.cc:}}[[@LINE-2]]
17
18   // CHECK: Uninitialized value was created by a heap allocation
19   // CHECK: {{#0 0x.* in .*realloc}}
20   // CHECK: {{#1 0x.* in main .*realloc-origin.cc:}}[[@LINE-9]]
21 }