[PATCH] D118657: [analyzer] Adds TrustReturnsNonnullChecker
Rashmi Mudduluru via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 1 12:00:36 PST 2022
t-rasmud updated this revision to Diff 405030.
t-rasmud added a comment.
This diff addresses review comments.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118657/new/
https://reviews.llvm.org/D118657
Files:
clang/lib/StaticAnalyzer/Checkers/TrustReturnsNonnullChecker.cpp
clang/test/Analysis/test-decl-crash.cpp
Index: clang/test/Analysis/test-decl-crash.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/test-decl-crash.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,apiModeling.TrustReturnsNonnull -verify %s
+
+// expected-no-diagnostics
+
+void test(void *(*f)(void)) {
+ // will probably crash the compiler, worth a test case
+ f();
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/TrustReturnsNonnullChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/TrustReturnsNonnullChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/TrustReturnsNonnullChecker.cpp
@@ -1,5 +1,4 @@
-//== TrustReturnsNonnullChecker.cpp --------- API nullability modeling -*- C++
-//-*--==//
+//== TrustReturnsNonnullChecker.cpp --------- API nullability modeling -*- C++ -*--==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -13,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
@@ -30,7 +30,7 @@
void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
ProgramStateRef State = C.getState();
- if (isNonNullPtr(Call, C))
+ if (isNonNullPtr(Call))
if (auto L = Call.getReturnValue().getAs<Loc>())
State = State->assume(*L, /*assumption=*/true);
@@ -39,16 +39,13 @@
private:
/// \returns Whether the method declaration has the attribute returns_nonnull.
- bool isNonNullPtr(const CallEvent &Call, CheckerContext &C) const {
+ bool isNonNullPtr(const CallEvent &Call) const {
QualType ExprRetType = Call.getResultType();
- if (!ExprRetType->isAnyPointerType())
+ const Decl *CallDeclaration = Call.getDecl();
+ if (!ExprRetType->isAnyPointerType() || !CallDeclaration)
return false;
- if (Call.getDecl()->hasAttr<ReturnsNonNullAttr>()) {
- return true;
- }
-
- return false;
+ return CallDeclaration->hasAttr<ReturnsNonNullAttr>();
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118657.405030.patch
Type: text/x-patch
Size: 2386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/ed212903/attachment.bin>
More information about the llvm-commits
mailing list