Files
clang-p2996/clang/test/Analysis/std-c-library-functions-path-notes.c
Balázs Kéri 4f0436dd15 [clang][analyzer] Merge apiModeling.StdCLibraryFunctions and StdCLibraryFunctionArgs checkers into one.
Main reason for this change is that these checkers were implemented in the same class
but had different dependency ordering. (NonNullParamChecker should run before StdCLibraryFunctionArgs
to get more special warning about null arguments, but the apiModeling.StdCLibraryFunctions was a modeling
checker that should run before other non-modeling checkers. The modeling checker changes state in a way
that makes it impossible to detect a null argument by NonNullParamChecker.)
To make it more simple, the modeling part is removed as separate checker and can be only used if
checker StdCLibraryFunctions is turned on, that produces the warnings too. Modeling the functions
without bug detection (for invalid argument) is not possible. The modeling of standard functions
does not happen by default from this change on.

Reviewed By: Szelethus

Differential Revision: https://reviews.llvm.org/D151225
2023-06-01 09:54:35 +02:00

61 lines
1.9 KiB
C

// RUN: %clang_analyze_cc1 -verify %s \
// RUN: -analyzer-checker=core,alpha.unix.StdCLibraryFunctions \
// RUN: -analyzer-output=text
#define NULL ((void *)0)
char *getenv(const char *);
int isalpha(int);
int isdigit(int);
int islower(int);
char test_getenv() {
char *env = getenv("VAR"); // \
// expected-note{{Assuming the environment variable does not exist}} \
// expected-note{{'env' initialized here}}
return env[0]; // \
// expected-warning{{Array access (from variable 'env') results in a null pointer dereference}} \
// expected-note {{Array access (from variable 'env') results in a null pointer dereference}}
}
int test_isalpha(int *x, char c) {
if (isalpha(c)) {// \
// expected-note{{Assuming the character is alphabetical}} \
// expected-note{{Taking true branch}}
x = NULL; // \
// expected-note{{Null pointer value stored to 'x'}}
}
return *x; // \
// expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
// expected-note {{Dereference of null pointer (loaded from variable 'x')}}
}
int test_isdigit(int *x, char c) {
if (!isdigit(c)) {// \
// expected-note{{Assuming the character is not a digit}} \
// expected-note{{Taking true branch}}
x = NULL; // \
// expected-note{{Null pointer value stored to 'x'}}
}
return *x; // \
// expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
// expected-note {{Dereference of null pointer (loaded from variable 'x')}}
}
int test_islower(int *x) {
char c = 'c';
// No "Assuming..." note. We aren't assuming anything. We *know*.
if (islower(c)) { // \
// expected-note{{Taking true branch}}
x = NULL; // \
// expected-note{{Null pointer value stored to 'x'}}
}
return *x; // \
// expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
// expected-note {{Dereference of null pointer (loaded from variable 'x')}}
}