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