| 1 |
// Check the case when only the StreamChecker is enabled. |
| 2 |
// RUN: %clang_analyze_cc1 %s \ |
| 3 |
// RUN: -analyzer-checker=core,unix.Stream \ |
| 4 |
// RUN: -analyzer-config unix.Stream:Pedantic=true \ |
| 5 |
// RUN: -analyzer-checker=debug.ExprInspection \ |
| 6 |
// RUN: -analyzer-config eagerly-assume=false \ |
| 7 |
// RUN: -triple x86_64-unknown-linux \ |
| 8 |
// RUN: -verify=stream |
| 9 |
|
| 10 |
// Check the case when only the StdLibraryFunctionsChecker is enabled. |
| 11 |
// RUN: %clang_analyze_cc1 %s \ |
| 12 |
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \ |
| 13 |
// RUN: -analyzer-config unix.StdCLibraryFunctions:DisplayLoadedSummaries=true \ |
| 14 |
// RUN: -analyzer-checker=debug.ExprInspection \ |
| 15 |
// RUN: -analyzer-config eagerly-assume=false \ |
| 16 |
// RUN: -triple x86_64-unknown-linux \ |
| 17 |
// RUN: -verify=stdLib 2>&1 | FileCheck %s |
| 18 |
|
| 19 |
// Check the case when both the StreamChecker and the |
| 20 |
// StdLibraryFunctionsChecker are enabled. |
| 21 |
// RUN: %clang_analyze_cc1 %s \ |
| 22 |
// RUN: -analyzer-checker=core,unix.Stream \ |
| 23 |
// RUN: -analyzer-config unix.Stream:Pedantic=true \ |
| 24 |
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \ |
| 25 |
// RUN: -analyzer-config unix.StdCLibraryFunctions:DisplayLoadedSummaries=true \ |
| 26 |
// RUN: -analyzer-checker=debug.ExprInspection \ |
| 27 |
// RUN: -analyzer-config eagerly-assume=false \ |
| 28 |
// RUN: -triple x86_64-unknown-linux \ |
| 29 |
// RUN: -verify=both 2>&1 | FileCheck %s |
| 30 |
|
| 31 |
// Verify that the summaries are loaded when the StdLibraryFunctionsChecker is |
| 32 |
// enabled. |
| 33 |
// CHECK: Loaded summary for: int getchar(void) |
| 34 |
// CHECK-NEXT: Loaded summary for: __size_t fread(void *restrict, size_t, size_t, FILE *restrict) |
| 35 |
// CHECK-NEXT: Loaded summary for: __size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict) |
| 36 |
|
| 37 |
#include "Inputs/system-header-simulator.h" |
| 38 |
|
| 39 |
void clang_analyzer_eval(int); |
| 40 |
|
| 41 |
void test_fread_fwrite(FILE *fp, int *buf) { |
| 42 |
fp = fopen("foo", "r"); |
| 43 |
if (!fp) |
| 44 |
return; |
| 45 |
size_t x = fwrite(buf, sizeof(int), 10, fp); |
| 46 |
|
| 47 |
clang_analyzer_eval(x <= 10); // \ |
| 48 |
// stream-warning{{TRUE}} \ |
| 49 |
// stdLib-warning{{TRUE}} \ |
| 50 |
// both-warning{{TRUE}} |
| 51 |
|
| 52 |
clang_analyzer_eval(x == 10); // \ |
| 53 |
// stream-warning{{TRUE}} \ |
| 54 |
// stream-warning{{FALSE}} \ |
| 55 |
// stdLib-warning{{TRUE}} \ |
| 56 |
// stdLib-warning{{FALSE}} \ |
| 57 |
// both-warning{{TRUE}} \ |
| 58 |
// both-warning{{FALSE}} |
| 59 |
|
| 60 |
fclose(fp); |
| 61 |
} |