Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / fread_fwrite.cpp
blob9980d114086bc77db5c7300c47e008d91b81010d
1 // RUN: %clangxx_msan -g %s -o %t
2 // RUN: not %run %t 2>&1 | FileCheck %s
3 // RUN: %t 1
5 #include <stdio.h>
6 #include <stdlib.h>
8 int test_fread() {
9 FILE *f = fopen("/dev/zero", "r");
10 char c;
11 unsigned read = fread(&c, sizeof(c), 1, f);
12 fclose(f);
13 if (c == '1') // No error
14 return 1;
15 return 0;
18 int test_fwrite() {
19 FILE *f = fopen("/dev/null", "w");
20 char c;
21 if (fwrite(&c, sizeof(c), 1, f) != sizeof(c)) // BOOM
22 return 1;
23 return fclose(f);
26 int main(int argc, char *argv[]) {
27 if (argc > 1)
28 test_fread();
29 else
30 test_fwrite();
31 return 0;
34 // CHECK: Uninitialized bytes in fwrite at offset 0 inside