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(size: 100); |
11 | p = (char *)realloc(ptr: p, size: 101); |
12 | char x = p[100]; |
13 | free(ptr: p); |
14 | return x; |
15 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value |
16 | // CHECK: {{#0 0x.* in main .*realloc-origin.cpp:}}[[@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.cpp:}}[[@LINE-9]] |
21 | } |
22 | |