Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / getline.cpp
blobee12d4ddc5298779293c618d59c5d981cd6b065d
1 // RUN: echo "abcde" > %t-testdata
2 // RUN: echo "12345" >> %t-testdata
3 // RUN: %clangxx_msan -O0 %s -o %t && %run %t %t-testdata
4 // RUN: %clangxx_msan -O2 %s -o %t && %run %t %t-testdata
5 // RUN: %clang_msan -O0 -xc %s -o %t && %run %t %t-testdata
6 // RUN: %clang_msan -O2 -xc %s -o %t && %run %t %t-testdata
7 // RUN: %clang_msan -O0 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
8 // RUN: %clang_msan -O2 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
10 #if defined(__FreeBSD__)
11 #define _WITH_GETLINE // To declare getline().
12 #endif
14 #include <assert.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
19 int main(int argc, char **argv) {
20 assert(argc == 2);
21 printf("%s\n", argv[1]);
23 FILE *fp = fopen(argv[1], "r");
24 assert(fp);
26 char *line = 0;
27 size_t len = 0;
28 int n = getline(&line, &len, fp);
29 assert(n == 6);
30 assert(strcmp(line, "abcde\n") == 0);
32 n = getline(&line, &len, fp);
33 assert(n == 6);
34 assert(strcmp(line, "12345\n") == 0);
36 free(line);
37 fclose(fp);
39 return 0;