[PATCH] D114560: [OPENMP]Fix PR51327: Range based for loop not working if range's type is a template.

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 24 12:26:06 PST 2021


ABataev created this revision.
ABataev added reviewers: jdoerfert, mikerice.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

Need to postpone anlysis of the ranged for loops till the actual
instantiation to avoid erroneous emission of error messages.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114560

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/for_loop_auto.cpp


Index: clang/test/OpenMP/for_loop_auto.cpp
===================================================================
--- /dev/null
+++ clang/test/OpenMP/for_loop_auto.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print -std=c++20 %s -Wsign-conversion | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++20 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++20 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print -std=c++20 %s -Wsign-conversion | FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++20 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -std=c++20 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+// CHECK:      template <> void do_loop(const auto &v) {
+// CHECK-NEXT: #pragma omp parallel for
+// CHECK-NEXT:    for (const auto &i : v)
+// CHECK-NEXT:      ;
+// CHECK-NEXT: }
+
+void do_loop(const auto &v) {
+#pragma omp parallel for
+  for (const auto &i : v)
+    ;
+}
+#endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -8804,6 +8804,9 @@
   }
   assert(((For && For->getBody()) || (CXXFor && CXXFor->getBody())) &&
          "No loop body.");
+  // Postpone analysis in dependent contexts for ranged for loops.
+  if (CXXFor && SemaRef.CurContext->isDependentContext())
+    return false;
 
   OpenMPIterationSpaceChecker ISC(SemaRef, SupportsNonRectangular, DSA,
                                   For ? For->getForLoc() : CXXFor->getForLoc());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114560.389592.patch
Type: text/x-patch
Size: 1689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211124/178708a5/attachment-0001.bin>


More information about the cfe-commits mailing list