Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / Linux / file.cpp
blobff1d334e8cbe1884655b399a62f267e62d71a4eb
1 // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
2 // RUN: %clangxx_msan -std=c++11 -fsanitize-memory-track-origins -O0 %s -o %t && %run %t
4 #include <assert.h>
5 #include <stdio.h>
7 #include <sanitizer/msan_interface.h>
9 int main(int argc, char *argv[]) {
10 FILE *f = fopen(argv[0], "r");
11 assert(f);
12 char buf[50];
13 fread(buf, 1, 1, f);
14 fflush(f);
16 assert(f->_IO_read_end > f->_IO_read_base);
17 __msan_check_mem_is_initialized(f->_IO_read_end, f->_IO_read_end - f->_IO_read_base);
19 char tmp_file[1000];
20 sprintf(tmp_file, "%s.write.tmp", argv[0]);
22 f = fopen(tmp_file, "w+");
23 assert(f);
24 fwrite(buf, 1, 1, f);
25 fflush(f);
27 assert(f->_IO_write_end > f->_IO_write_base);
28 __msan_check_mem_is_initialized(f->_IO_write_end, f->_IO_write_end - f->_IO_write_base);