r194004 - [analyzer] Suppress warnings coming out of std::basic_string.
Anna Zaks
ganna at apple.com
Mon Nov 4 11:13:03 PST 2013
Author: zaks
Date: Mon Nov 4 13:13:03 2013
New Revision: 194004
URL: http://llvm.org/viewvc/llvm-project?rev=194004&view=rev
Log:
[analyzer] Suppress warnings coming out of std::basic_string.
The analyzer cannot reason about the internal invariances of the data structure (radar://15194597).
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
cfe/trunk/test/Analysis/inlining/stl.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=194004&r1=194003&r2=194004&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Nov 4 13:13:03 2013
@@ -1549,6 +1549,18 @@ LikelyFalsePositiveSuppressionBRVisitor:
return 0;
}
}
+ // The analyzer issues a false positive on
+ // std::basic_string<uint8_t> v; v.push_back(1);
+ // because we cannot reason about the internal invariants of the
+ // datastructure.
+ if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
+ const CXXRecordDecl *CD = MD->getParent();
+ if (CD->getName() == "basic_string") {
+ BR.markInvalid(getTag(), 0);
+ return 0;
+ }
+ }
+
}
}
Modified: cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=194004&r1=194003&r2=194004&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h (original)
+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h Mon Nov 4 13:13:03 2013
@@ -5,6 +5,8 @@
// suppressed.
#pragma clang system_header
+typedef unsigned char uint8_t;
+
namespace std {
template <class T1, class T2>
struct pair {
@@ -137,6 +139,20 @@ namespace std {
bool empty() const;
};
+ // basic_string
+ template<class _CharT>
+ class __attribute__ ((__type_visibility__("default"))) basic_string {
+ public:
+ void push_back(int c);
+ };
+ template <class _CharT>
+ void basic_string<_CharT>::push_back(int __c) {
+ // Fake error trigger.
+ // No warning is expected as we are suppressing warning comming
+ // out of std::basic_string.
+ int z = 0;
+ z = 5/z;
+ }
}
void* operator new(std::size_t, const std::nothrow_t&) throw();
Modified: cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp?rev=194004&r1=194003&r2=194004&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp Mon Nov 4 13:13:03 2013
@@ -12,6 +12,6 @@ void clang_analyzer_eval(bool);
void testCopyNull(int *I, int *E) {
std::copy(I, E, (int *)0);
#ifndef SUPPRESSED
- // expected-warning at ../Inputs/system-header-simulator-cxx.h:108 {{Dereference of null pointer}}
+ // expected-warning at ../Inputs/system-header-simulator-cxx.h:110 {{Dereference of null pointer}}
#endif
}
Modified: cfe/trunk/test/Analysis/inlining/stl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/stl.cpp?rev=194004&r1=194003&r2=194004&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/stl.cpp (original)
+++ cfe/trunk/test/Analysis/inlining/stl.cpp Mon Nov 4 13:13:03 2013
@@ -33,3 +33,8 @@ void testList_pop_front(std::list<int> l
list.pop_front(); // no-warning
}
+void testBasicStringSuppression() {
+ std::basic_string<uint8_t> v;
+ v.push_back(1); // no-warning
+}
+
More information about the cfe-commits
mailing list