<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 7, 2014 at 9:35 AM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jrose<br>
Date: Fri Feb 7 11:35:04 2014<br>
New Revision: 200980<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=200980&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=200980&view=rev</a><br>
Log:<br>
[analyzer] Just silence all warnings coming out of std::basic_string.<br></blockquote><div><br></div><div>This does seem like a rather rough heuristic - is there nothing better? (more general - everything in the STL? What about every other string class everyone and their monkey have written? And I assume this isn't about strings, as such, but just a complexity problem with complex types and string just happens to be a commonly used one?) </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This means always walking the whole call stack for the end path node, but<br>
we'll assume that's always fairly tractable.<br>
<br>
<rdar://problem/15952973><br>
<br>
Modified:<br>
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp<br>
cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h<br>
cfe/trunk/test/Analysis/inlining/stl.cpp<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=200980&r1=200979&r2=200980&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=200980&r1=200979&r2=200980&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Feb 7 11:35:04 2014<br>
@@ -1558,25 +1558,18 @@ LikelyFalsePositiveSuppressionBRVisitor:<br>
// std::u16string s; s += u'a';<br>
// because we cannot reason about the internal invariants of the<br>
// datastructure.<br>
- const LocationContext *LCtx = N->getLocationContext();<br>
- do {<br>
+ for (const LocationContext *LCtx = N->getLocationContext(); LCtx;<br>
+ LCtx = LCtx->getParent()) {<br>
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(LCtx->getDecl());<br>
if (!MD)<br>
- break;<br>
+ continue;<br>
<br>
const CXXRecordDecl *CD = MD->getParent();<br>
if (CD->getName() == "basic_string") {<br>
BR.markInvalid(getTag(), 0);<br>
return 0;<br>
- } else if (CD->getName().find("allocator") == StringRef::npos) {<br>
- // Only keep searching if the current method is in a class with the<br>
- // word "allocator" in its name, e.g. std::allocator or<br>
- // allocator_traits.<br>
- break;<br>
}<br>
-<br>
- LCtx = LCtx->getParent();<br>
- } while (LCtx);<br>
+ }<br>
}<br>
}<br>
<br>
<br>
Modified: cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=200980&r1=200979&r2=200980&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=200980&r1=200979&r2=200980&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h (original)<br>
+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h Fri Feb 7 11:35:04 2014<br>
@@ -155,11 +155,21 @@ namespace std {<br>
// basic_string<br>
template<class _CharT, class _Alloc = allocator<_CharT> ><br>
class __attribute__ ((__type_visibility__("default"))) basic_string {<br>
- _CharT localStorage[4];<br>
+ bool isLong;<br>
+ union {<br>
+ _CharT localStorage[4];<br>
+ _CharT *externalStorage;<br>
+<br>
+ void assignExternal(_CharT *newExternal) {<br>
+ externalStorage = newExternal;<br>
+ }<br>
+ } storage;<br>
<br>
typedef allocator_traits<_Alloc> __alloc_traits;<br>
<br>
public:<br>
+ basic_string();<br>
+<br>
void push_back(int c) {<br>
// Fake error trigger.<br>
// No warning is expected as we are suppressing warning coming<br>
@@ -168,11 +178,24 @@ namespace std {<br>
z = 5/z;<br>
}<br>
<br>
+ _CharT *getBuffer() {<br>
+ return isLong ? storage.externalStorage : storage.localStorage;<br>
+ }<br>
+<br>
basic_string &operator +=(int c) {<br>
// Fake deallocate stack-based storage.<br>
// No warning is expected as we are suppressing warnings within<br>
- // allocators being used by std::basic_string.<br>
- __alloc_traits::deallocate(&localStorage);<br>
+ // std::basic_string.<br>
+ __alloc_traits::deallocate(getBuffer());<br>
+ }<br>
+<br>
+ basic_string &operator =(const basic_string &other) {<br>
+ // Fake deallocate stack-based storage, then use the variable in the<br>
+ // same union.<br>
+ // No warning is expected as we are suppressing warnings within<br>
+ // std::basic_string.<br>
+ __alloc_traits::deallocate(getBuffer());<br>
+ storage.assignExternal(new _CharT[4]);<br>
}<br>
};<br>
}<br>
<br>
Modified: cfe/trunk/test/Analysis/inlining/stl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/stl.cpp?rev=200980&r1=200979&r2=200980&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/stl.cpp?rev=200980&r1=200979&r2=200980&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/inlining/stl.cpp (original)<br>
+++ cfe/trunk/test/Analysis/inlining/stl.cpp Fri Feb 7 11:35:04 2014<br>
@@ -42,3 +42,8 @@ void testBasicStringSuppression_append()<br>
std::basic_string<char32_t> v;<br>
v += 'c'; // no-warning<br>
}<br>
+<br>
+void testBasicStringSuppression_assign(std::basic_string<char32_t> &v,<br>
+ const std::basic_string<char32_t> &v2) {<br>
+ v = v2;<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>