221
|
1 // Check that the more specific checkers report and not the generic
|
|
2 // StdCLibraryFunctionArgs checker.
|
|
3
|
|
4 // RUN: %clang_analyze_cc1 %s \
|
|
5 // RUN: -analyzer-checker=core \
|
|
6 // RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
|
|
7 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
|
|
8 // RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
|
|
9 // RUN: -analyzer-checker=alpha.unix.Stream \
|
|
10 // RUN: -triple x86_64-unknown-linux-gnu \
|
|
11 // RUN: -verify
|
|
12
|
|
13
|
|
14 // Make sure that all used functions have their summary loaded.
|
|
15
|
|
16 // RUN: %clang_analyze_cc1 %s \
|
|
17 // RUN: -analyzer-checker=core \
|
|
18 // RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
|
|
19 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
|
|
20 // RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
|
|
21 // RUN: -analyzer-checker=alpha.unix.Stream \
|
|
22 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
|
|
23 // RUN: -triple x86_64-unknown-linux 2>&1 | FileCheck %s
|
|
24
|
|
25 // CHECK: Loaded summary for: int isalnum(int)
|
|
26 // CHECK: Loaded summary for: unsigned long fread(void *restrict, size_t, size_t, FILE *restrict) __attribute__((nonnull(1)))
|
|
27 // CHECK: Loaded summary for: int fileno(FILE *stream)
|
|
28
|
|
29 void initializeSummaryMap();
|
|
30 // We analyze this function first, and the call expression inside initializes
|
|
31 // the summary map. This way we force the loading of the summaries. The
|
|
32 // summaries would not be loaded without this because during the first bug
|
|
33 // report in WeakDependency::checkPreCall we stop further evaluation. And
|
|
34 // StdLibraryFunctionsChecker lazily initializes its summary map from its
|
|
35 // checkPreCall.
|
|
36 void analyzeThisFirst() {
|
|
37 initializeSummaryMap();
|
|
38 }
|
|
39
|
|
40 typedef __typeof(sizeof(int)) size_t;
|
|
41 struct FILE;
|
|
42 typedef struct FILE FILE;
|
|
43
|
|
44 int isalnum(int);
|
|
45 size_t fread(void *restrict, size_t, size_t, FILE *restrict) __attribute__((nonnull(1)));
|
|
46 int fileno(FILE *stream);
|
|
47
|
|
48 void test_uninit_arg() {
|
|
49 int v;
|
|
50 int r = isalnum(v); // \
|
|
51 // expected-warning{{1st function call argument is an uninitialized value [core.CallAndMessage]}}
|
|
52 (void)r;
|
|
53 }
|
|
54
|
|
55 void test_notnull_arg(FILE *F) {
|
|
56 int *p = 0;
|
|
57 fread(p, sizeof(int), 5, F); // \
|
|
58 expected-warning{{Null pointer passed to 1st parameter expecting 'nonnull' [core.NonNullParamChecker]}}
|
|
59 }
|
|
60
|
|
61 void test_notnull_stream_arg() {
|
|
62 fileno(0); // \
|
|
63 // expected-warning{{Stream pointer might be NULL [alpha.unix.Stream]}}
|
|
64 }
|