[PATCH] D50408: [analyzer] Avoid querying this-pointers for static-methods.

2018-08-07 Thread Matt Davis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339201: [analyzer] Avoid querying this-pointers for 
static-methods. (authored by mattd, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D50408

Files:
  lib/StaticAnalyzer/Core/LoopWidening.cpp
  test/Analysis/loop-widening-ignore-static-methods.cpp


Index: test/Analysis/loop-widening-ignore-static-methods.cpp
===
--- test/Analysis/loop-widening-ignore-static-methods.cpp
+++ test/Analysis/loop-widening-ignore-static-methods.cpp
@@ -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 (;;) {}
+  }
+};
Index: lib/StaticAnalyzer/Core/LoopWidening.cpp
===
--- lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -81,8 +81,10 @@
 
   // '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(STC->getDecl())) {
+  // pointer should remain unchanged.  Ignore static methods, since they do not
+  // have 'this' pointers.
+  const CXXMethodDecl *CXXMD = dyn_cast(STC->getDecl());
+  if (CXXMD && !CXXMD->isStatic()) {
 const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion(
 CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()),
 STC);


Index: test/Analysis/loop-widening-ignore-static-methods.cpp
===
--- test/Analysis/loop-widening-ignore-static-methods.cpp
+++ test/Analysis/loop-widening-ignore-static-methods.cpp
@@ -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 (;;) {}
+  }
+};
Index: lib/StaticAnalyzer/Core/LoopWidening.cpp
===
--- lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -81,8 +81,10 @@
 
   // '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(STC->getDecl())) {
+  // pointer should remain unchanged.  Ignore static methods, since they do not
+  // have 'this' pointers.
+  const CXXMethodDecl *CXXMD = dyn_cast(STC->getDecl());
+  if (CXXMD && !CXXMD->isStatic()) {
 const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion(
 CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()),
 STC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50408: [analyzer] Avoid querying this-pointers for static-methods.

2018-08-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Yup, fair enough.


https://reviews.llvm.org/D50408



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50408: [analyzer] Avoid querying this-pointers for static-methods.

2018-08-07 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a reviewer: NoQ.
george.karpenkov added a subscriber: NoQ.
george.karpenkov added a comment.

Looks reasonable. @NoQ any further comments?


https://reviews.llvm.org/D50408



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50408: [analyzer] Avoid querying this-pointers for static-methods.

2018-08-07 Thread Matt Davis via Phabricator via cfe-commits
mattd created this revision.
mattd added a reviewer: dcoughlin.
Herald added subscribers: mikhail.ramalho, a.sidorin, szepet, xazax.hun.
Herald added a reviewer: george.karpenkov.

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 .


https://reviews.llvm.org/D50408

Files:
  lib/StaticAnalyzer/Core/LoopWidening.cpp
  test/Analysis/loop-widening-ignore-static-methods.cpp


Index: test/Analysis/loop-widening-ignore-static-methods.cpp
===
--- test/Analysis/loop-widening-ignore-static-methods.cpp
+++ test/Analysis/loop-widening-ignore-static-methods.cpp
@@ -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 (;;) {}
+  }
+};
Index: lib/StaticAnalyzer/Core/LoopWidening.cpp
===
--- lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -81,8 +81,10 @@
 
   // '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(STC->getDecl())) {
+  // pointer should remain unchanged.  Ignore static methods, since they do not
+  // have 'this' pointers.
+  const CXXMethodDecl *CXXMD = dyn_cast(STC->getDecl());
+  if (CXXMD && !CXXMD->isStatic()) {
 const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion(
 CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()),
 STC);


Index: test/Analysis/loop-widening-ignore-static-methods.cpp
===
--- test/Analysis/loop-widening-ignore-static-methods.cpp
+++ test/Analysis/loop-widening-ignore-static-methods.cpp
@@ -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 (;;) {}
+  }
+};
Index: lib/StaticAnalyzer/Core/LoopWidening.cpp
===
--- lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -81,8 +81,10 @@
 
   // '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(STC->getDecl())) {
+  // pointer should remain unchanged.  Ignore static methods, since they do not
+  // have 'this' pointers.
+  const CXXMethodDecl *CXXMD = dyn_cast(STC->getDecl());
+  if (CXXMD && !CXXMD->isStatic()) {
 const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion(
 CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()),
 STC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits