Author: mattd Date: Tue Aug 7 16:13:28 2018 New Revision: 339201 URL: http://llvm.org/viewvc/llvm-project?rev=339201&view=rev Log: [analyzer] Avoid querying this-pointers for static-methods.
Summary: The loop-widening code processes c++ methods looking for `this` pointers. In the case of static methods (which do not have `this` pointers), an assertion was triggering. This patch avoids trying to process `this` pointers for static methods, and thus avoids triggering the assertion . Reviewers: dcoughlin, george.karpenkov, NoQ Reviewed By: NoQ Subscribers: NoQ, xazax.hun, szepet, a.sidorin, mikhail.ramalho, cfe-commits Differential Revision: https://reviews.llvm.org/D50408 Added: cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp?rev=339201&r1=339200&r2=339201&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp Tue Aug 7 16:13:28 2018 @@ -81,8 +81,10 @@ ProgramStateRef getWidenedLoopState(Prog // 'this' pointer is not an lvalue, we should not invalidate it. If the loop // is located in a method, constructor or destructor, the value of 'this' - // pointer shoule remain unchanged. - if (const CXXMethodDecl *CXXMD = dyn_cast<CXXMethodDecl>(STC->getDecl())) { + // pointer should remain unchanged. Ignore static methods, since they do not + // have 'this' pointers. + const CXXMethodDecl *CXXMD = dyn_cast<CXXMethodDecl>(STC->getDecl()); + if (CXXMD && !CXXMD->isStatic()) { const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion( CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()), STC); Added: cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp?rev=339201&view=auto ============================================================================== --- cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp (added) +++ cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp Tue Aug 7 16:13:28 2018 @@ -0,0 +1,12 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config widen-loops=true -analyzer-max-loop 2 %s +// REQUIRES: asserts +// expected-no-diagnostics +// +// This test checks that the loop-widening code ignores static methods. If that is not the +// case, then an assertion will trigger. + +class Test { + static void foo() { + for (;;) {} + } +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits