[OPENMP]Fix crash in LoopCounterRefChecker when MemberExpr is not Var or Field
authorMike Rice <michael.p.rice@intel.com>
Wed, 17 Jul 2019 15:18:45 +0000 (15:18 +0000)
committerMike Rice <michael.p.rice@intel.com>
Wed, 17 Jul 2019 15:18:45 +0000 (15:18 +0000)
checkDecl is only valid for VarDecls or FieldDecls, since getCanonicalDecl
expects only these. Prevent other Decl kinds (such as CXXMethodDecls and
EnumConstantDecls) from entering and asserting.

Differential Revision: https://reviews.llvm.org/D64842

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366336 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOpenMP.cpp
test/OpenMP/for_loop_messages.cpp

index 222d042b6da5973ea5e3f0fc04c051970d31f358..bd68011c18b2312eb3207ac172f2ad06130946a1 100644 (file)
@@ -4992,7 +4992,8 @@ public:
   bool VisitMemberExpr(const MemberExpr *E) {
     if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) {
       const ValueDecl *VD = E->getMemberDecl();
-      return checkDecl(E, VD);
+      if (isa<VarDecl>(VD) || isa<FieldDecl>(VD))
+        return checkDecl(E, VD);
     }
     return false;
   }
index 7c2663f61816f70b024e8f4a9727131c71cfbbe5..f5f6d0b703136e47320156ff6246b2b43b7fe208 100644 (file)
@@ -626,6 +626,8 @@ template <typename IT, int ST>
 class TC {
   int ii, iii, kk;
 public:
+  enum { myconstant = 42 };
+  int ub();
   int dotest_lt(IT begin, IT end) {
 #pragma omp parallel
 // expected-error@+3 3 {{the loop initializer expression depends on the current loop control variable}}
@@ -634,6 +636,12 @@ public:
   for (ii = ii * 10 + 25; ii < ii / ii - 23; ii += 1)
     ;
 
+// Check that member function calls and enum constants in the condition is
+// handled.
+#pragma omp for
+  for (ii = 0; ii < ub() + this->myconstant; ii += 1) // expected-no-error
+    ;
+
 #pragma omp parallel
 // expected-error@+4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
 // expected-error@+3 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}}