Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / std-c-library-functions-vs-stream-checker.c
blob281fbaaffe70340f2354f9a42fd62a54fa95af38
1 // Check the case when only the StreamChecker is enabled.
2 // RUN: %clang_analyze_cc1 %s \
3 // RUN: -analyzer-checker=core,alpha.unix.Stream \
4 // RUN: -analyzer-checker=debug.ExprInspection \
5 // RUN: -analyzer-config eagerly-assume=false \
6 // RUN: -triple x86_64-unknown-linux \
7 // RUN: -verify=stream
9 // Check the case when only the StdLibraryFunctionsChecker is enabled.
10 // RUN: %clang_analyze_cc1 %s \
11 // RUN: -analyzer-checker=unix.StdCLibraryFunctions \
12 // RUN: -analyzer-config unix.StdCLibraryFunctions:DisplayLoadedSummaries=true \
13 // RUN: -analyzer-checker=debug.ExprInspection \
14 // RUN: -analyzer-config eagerly-assume=false \
15 // RUN: -triple x86_64-unknown-linux \
16 // RUN: -verify=stdLib 2>&1 | FileCheck %s
18 // Check the case when both the StreamChecker and the
19 // StdLibraryFunctionsChecker are enabled.
20 // RUN: %clang_analyze_cc1 %s \
21 // RUN: -analyzer-checker=core,alpha.unix.Stream \
22 // RUN: -analyzer-checker=unix.StdCLibraryFunctions \
23 // RUN: -analyzer-config unix.StdCLibraryFunctions:DisplayLoadedSummaries=true \
24 // RUN: -analyzer-checker=debug.ExprInspection \
25 // RUN: -analyzer-config eagerly-assume=false \
26 // RUN: -triple x86_64-unknown-linux \
27 // RUN: -verify=both 2>&1 | FileCheck %s
29 // Verify that the summaries are loaded when the StdLibraryFunctionsChecker is
30 // enabled.
31 // CHECK: Loaded summary for: int getchar(void)
32 // CHECK-NEXT: Loaded summary for: unsigned long fread(void *restrict, size_t, size_t, FILE *restrict)
33 // CHECK-NEXT: Loaded summary for: unsigned long fwrite(const void *restrict, size_t, size_t, FILE *restrict)
35 #include "Inputs/system-header-simulator.h"
37 void clang_analyzer_eval(int);
39 void test_fread_fwrite(FILE *fp, int *buf) {
40 fp = fopen("foo", "r");
41 if (!fp)
42 return;
43 size_t x = fwrite(buf, sizeof(int), 10, fp);
45 clang_analyzer_eval(x <= 10); // \
46 // stream-warning{{TRUE}} \
47 // stdLib-warning{{TRUE}} \
48 // both-warning{{TRUE}}
50 clang_analyzer_eval(x == 10); // \
51 // stream-warning{{TRUE}} \
52 // stream-warning{{FALSE}} \
53 // stdLib-warning{{TRUE}} \
54 // stdLib-warning{{FALSE}} \
55 // both-warning{{TRUE}} \
56 // both-warning{{FALSE}}
58 fclose(fp);