Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / fgets_fputs.cpp
blobe050234ed2393846c0c69443b64415eb89984875
1 // RUN: %clangxx_msan -g %s -o %t
2 // RUN: %run %t
3 // RUN: not %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-FPUTS
4 // RUN: not %run %t 3 3 2>&1 | FileCheck %s --check-prefix=CHECK-PUTS
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 int test_fgets() {
11 FILE *fp = fopen("/dev/zero", "r");
12 char c;
14 if (!fgets(&c, 1, fp))
15 return 1;
17 if (c == '1') // No error
18 return 2;
20 fclose(fp);
21 return 0;
24 int test_fputs() {
25 FILE *fp = fopen("/dev/null", "w");
26 char buf[2];
27 fputs(buf, fp); // BOOM
28 return fclose(fp);
31 void test_puts() {
32 char buf[2];
33 puts(buf); // BOOM
36 int main(int argc, char *argv[]) {
37 if (argc == 1)
38 test_fgets();
39 else if (argc == 2)
40 test_fputs();
41 else
42 test_puts();
43 return 0;
46 // CHECK-FPUTS: Uninitialized bytes in fputs at offset 0 inside
47 // CHECK-PUTS: Uninitialized bytes in puts at offset 0 inside