[PATCH] D62926: [analyzer] ReturnVisitor: Bypass everything to see inlined calls
Csaba Dabis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 10 12:38:36 PDT 2019
Charusso updated this revision to Diff 203874.
Charusso retitled this revision from "[analyzer] ReturnVisitor: Bypass constructing objects to see inlined calls" to "[analyzer] ReturnVisitor: Bypass everything to see inlined calls".
Charusso added a comment.
- The most generic approach.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62926/new/
https://reviews.llvm.org/D62926
Files:
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/test/Analysis/new-ctor-null-throw.cpp
clang/test/Analysis/new-ctor-null.cpp
Index: clang/test/Analysis/new-ctor-null.cpp
===================================================================
--- clang/test/Analysis/new-ctor-null.cpp
+++ clang/test/Analysis/new-ctor-null.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 \
+// RUN: -analyzer-checker=core,debug.ExprInspection \
+// RUN: -verify %s
void clang_analyzer_eval(bool);
void clang_analyzer_warnIfReached();
@@ -24,7 +26,8 @@
void testArrays() {
S *s = new S[10]; // no-crash
- s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+ s[0].x = 2;
+ // no-warning: 'Dereference of null pointer' suppressed by ReturnVisitor.
}
int global;
Index: clang/test/Analysis/new-ctor-null-throw.cpp
===================================================================
--- clang/test/Analysis/new-ctor-null-throw.cpp
+++ clang/test/Analysis/new-ctor-null-throw.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN: -analyzer-config suppress-null-return-paths=false \
+// RUN: -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN: -DSUPPRESSED \
+// RUN: -verify %s
void clang_analyzer_eval(bool);
@@ -9,18 +14,41 @@
// operator new.
void *operator new(size_t size) {
return nullptr;
+ // expected-warning at -1 {{'operator new' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
}
void *operator new[](size_t size) {
return nullptr;
+ // expected-warning at -1 {{'operator new[]' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
}
struct S {
int x;
S() : x(1) {}
~S() {}
+ int getX() const { return x; }
};
void testArrays() {
S *s = new S[10]; // no-crash
- s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+ s[0].x = 2;
+#ifndef SUPPRESSED
+ // expected-warning at -2 {{Dereference of null pointer}}
+#endif
}
+
+void testCtor() {
+ S *s = new S();
+ s->x = 13;
+#ifndef SUPPRESSED
+ // expected-warning at -2 {{Access to field 'x' results in a dereference of a null pointer (loaded from variable 's')}}
+#endif
+}
+
+void testMethod() {
+ S *s = new S();
+ const int X = s->getX();
+#ifndef SUPPRESSED
+ // expected-warning at -2 {{Called C++ object pointer is null}}
+#endif
+}
+
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -834,12 +834,9 @@
// First, find when we processed the statement.
do {
- if (auto CEE = Node->getLocationAs<CallExitEnd>())
+ if (Optional<CallExitEnd> CEE = Node->getLocationAs<CallExitEnd>())
if (CEE->getCalleeContext()->getCallSite() == S)
break;
- if (auto SP = Node->getLocationAs<StmtPoint>())
- if (SP->getStmt() == S)
- break;
Node = Node->getFirstPred();
} while (Node);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62926.203874.patch
Type: text/x-patch
Size: 3223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190610/e30ad30b/attachment.bin>
More information about the cfe-commits
mailing list