forked from OSchip/llvm-project
[analyzer] Suppress warnings coming out of std::basic_string.
The analyzer cannot reason about the internal invariances of the data structure (radar://15194597). llvm-svn: 194004
This commit is contained in:
parent
5efbc6379e
commit
830d2f7701
|
@ -1549,6 +1549,18 @@ LikelyFalsePositiveSuppressionBRVisitor::getEndPath(BugReporterContext &BRC,
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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@../Inputs/system-header-simulator-cxx.h:108 {{Dereference of null pointer}}
|
||||
// expected-warning@../Inputs/system-header-simulator-cxx.h:110 {{Dereference of null pointer}}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -33,3 +33,8 @@ void testList_pop_front(std::list<int> list) {
|
|||
list.pop_front(); // no-warning
|
||||
}
|
||||
|
||||
void testBasicStringSuppression() {
|
||||
std::basic_string<uint8_t> v;
|
||||
v.push_back(1); // no-warning
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue