62 lines · c
1// Check that the more specific checkers report and not the generic2// StdCLibraryFunctions checker.3 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: -verify11 12 13// Make sure that all used functions have their summary loaded.14 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 %s21 22// CHECK: Loaded summary for: int isalnum(int)23// CHECK: Loaded summary for: __size_t fread(void *restrict, size_t, size_t, FILE *restrict) __attribute__((nonnull(1)))24// CHECK: Loaded summary for: int fileno(FILE *stream)25 26void initializeSummaryMap(void);27// We analyze this function first, and the call expression inside initializes28// the summary map. This way we force the loading of the summaries. The29// summaries would not be loaded without this because during the first bug30// report in WeakDependency::checkPreCall we stop further evaluation. And31// StdLibraryFunctionsChecker lazily initializes its summary map from its32// checkPreCall.33void analyzeThisFirst(void) {34 initializeSummaryMap();35}36 37typedef __typeof(sizeof(int)) size_t;38struct FILE;39typedef struct FILE FILE;40 41int isalnum(int);42size_t fread(void *restrict, size_t, size_t, FILE *restrict) __attribute__((nonnull(1)));43int fileno(FILE *stream);44 45void 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;50}51 52void 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]}}56}57 58void test_notnull_stream_arg(void) {59 fileno(0); // \60 // expected-warning{{Stream pointer might be NULL [unix.Stream]}}61}62