[clang] ab1fad8 - [analyzer] StdLibraryFunctionsChecker: Add test for function with default parameter
Gabor Marton via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 6 08:09:11 PDT 2020
Author: Gabor Marton
Date: 2020-04-06T17:08:58+02:00
New Revision: ab1fad8a3a8b8e3264c34448205061add013b8d7
URL: https://github.com/llvm/llvm-project/commit/ab1fad8a3a8b8e3264c34448205061add013b8d7
DIFF: https://github.com/llvm/llvm-project/commit/ab1fad8a3a8b8e3264c34448205061add013b8d7.diff
LOG: [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
Added:
clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index f03696daab0b..6ca664a28351 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -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 =
diff --git a/clang/test/Analysis/std-c-library-functions-arg-constraints.cpp b/clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
new file mode 100644
index 000000000000..fed815f67a57
--- /dev/null
+++ b/clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
@@ -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}}
+}
More information about the cfe-commits
mailing list