Author: zaks Date: Tue Jan 5 18:32:52 2016 New Revision: 256886 URL: http://llvm.org/viewvc/llvm-project?rev=256886&view=rev Log: [analyzer] Suppress reports coming from std::__independent_bits_engine
The analyzer reports a shift by a negative value in the constructor. The bug can be easily triggered by calling std::random_shuffle on a vector (<rdar://problem/19658126>). (The shift by a negative value is reported because __w0_ gets constrained to 63 by the conditions along the path:__w0_ < _WDt && __w0_ >= _WDt-1, where _WDt is 64. In normal execution, __w0_ is not 63, it is 1 and there is no overflow. The path is infeasible, but the analyzer does not know about that.) Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h 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=256886&r1=256885&r2=256886&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Jan 5 18:32:52 2016 @@ -1542,6 +1542,16 @@ LikelyFalsePositiveSuppressionBRVisitor: } } + // The analyzer issues a false positive when the constructor of + // std::__independent_bits_engine from algorithms is used. + if (const CXXConstructorDecl *MD = dyn_cast<CXXConstructorDecl>(D)) { + const CXXRecordDecl *CD = MD->getParent(); + if (CD->getName() == "__independent_bits_engine") { + BR.markInvalid(getTag(), nullptr); + return nullptr; + } + } + // The analyzer issues a false positive on // std::basic_string<uint8_t> v; v.push_back(1); // and 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=256886&r1=256885&r2=256886&view=diff ============================================================================== --- cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h (original) +++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h Tue Jan 5 18:32:52 2016 @@ -198,6 +198,25 @@ namespace std { storage.assignExternal(new _CharT[4]); } }; + +template<class _Engine, class _UIntType> +class __independent_bits_engine { +public: + // constructors and seeding functions + __independent_bits_engine(_Engine& __e, size_t __w); +}; + +template<class _Engine, class _UIntType> +__independent_bits_engine<_Engine, _UIntType> + ::__independent_bits_engine(_Engine& __e, size_t __w) +{ + // Fake error trigger. + // No warning is expected as we are suppressing warning coming + // 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/inlining/stl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/stl.cpp?rev=256886&r1=256885&r2=256886&view=diff ============================================================================== --- cfe/trunk/test/Analysis/inlining/stl.cpp (original) +++ cfe/trunk/test/Analysis/inlining/stl.cpp Tue Jan 5 18:32:52 2016 @@ -47,3 +47,8 @@ void testBasicStringSuppression_assign(s const std::basic_string<char32_t> &v2) { v = v2; } + +class MyEngine; +void testSupprerssion_independent_bits_engine(MyEngine& e) { + std::__independent_bits_engine<MyEngine, unsigned int> x(e, 64); // no-warning +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits