[analyzer] StdLibraryFunctionsChecker: Add test for function with default parameter

Reviewers: Szelethus, baloghadamsoftware, gamesh411, steakhal, balazske

Subscribers: whisperity, xazax.hun, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, Charusso, ASDenysPetrov, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77411
This commit is contained in:
Gabor Marton 2020-04-03 17:56:28 +02:00
parent 90be3c24a7
commit ab1fad8a3a
2 changed files with 21 additions and 0 deletions

View File

@ -960,6 +960,9 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ArgumentCondition(0U, OutOfRange, SingleValue(1)))
.ArgConstraint(
ArgumentCondition(0U, OutOfRange, SingleValue(2)))}},
{"__defaultparam", Summaries{Summary(ArgTypes{Irrelevant, IntTy},
RetType{IntTy}, EvalCallAsPure)
.ArgConstraint(NotNull(ArgNo(0)))}},
};
for (auto &E : TestFunctionSummaryMap) {
auto InsertRes =

View File

@ -0,0 +1,18 @@
// RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \
// RUN: -analyzer-checker=debug.ExprInspection \
// RUN: -analyzer-config eagerly-assume=false \
// RUN: -triple i686-unknown-linux \
// RUN: -verify
void clang_analyzer_eval(int);
int __defaultparam(void *, int y = 3);
void test_arg_constraint_on_fun_with_default_param() {
__defaultparam(nullptr); // \
// expected-warning{{Function argument constraint is not satisfied}}
}