[clang] [Clang][OpenMP] Fix the wrong transform of `num_teams` claused introduced in #99732 (PR #102716)

Shilei Tian via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 10 18:42:39 PDT 2024


https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/102716

>From 838e1ccc1593a12107fd96b36eea048dd9d38869 Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Fri, 9 Aug 2024 23:11:43 -0400
Subject: [PATCH] [Clang][OpenMP] Fix the wrong transform of `num_teams`
 claused introduced in #99732

---
 clang/lib/Sema/TreeTransform.h               | 13 +++++++++----
 clang/test/OpenMP/target_teams_ast_print.cpp |  4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 78ec964037dfe..62287c2d26375 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -11018,11 +11018,16 @@ TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
 template <typename Derived>
 OMPClause *
 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
-  ExprResult E = getDerived().TransformExpr(C->getNumTeams().front());
-  if (E.isInvalid())
-    return nullptr;
+  llvm::SmallVector<Expr *, 3> Vars;
+  Vars.reserve(C->varlist_size());
+  for (auto *VE : C->varlist()) {
+    ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
+    if (EVar.isInvalid())
+      return nullptr;
+    Vars.push_back(EVar.get());
+  }
   return getDerived().RebuildOMPNumTeamsClause(
-      E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
+      Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
 }
 
 template <typename Derived>
diff --git a/clang/test/OpenMP/target_teams_ast_print.cpp b/clang/test/OpenMP/target_teams_ast_print.cpp
index ca5d26822ec96..55ef532142dc6 100644
--- a/clang/test/OpenMP/target_teams_ast_print.cpp
+++ b/clang/test/OpenMP/target_teams_ast_print.cpp
@@ -58,6 +58,8 @@ T tmain(T argc, T *argv) {
   foo();
 #pragma omp target teams allocate(my_allocator:f) reduction(^:e, f) reduction(&& : g) uses_allocators(my_allocator(traits))
   foo();
+#pragma omp target teams ompx_bare num_teams(C, C, C) thread_limit(d*C, d*C, d*C)
+  foo();
   return 0;
 }
 
@@ -97,6 +99,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits))
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target teams ompx_bare num_teams(1,1,1) thread_limit(d * 1,d * 1,d * 1)
+// CHECK-NEXT:   foo();
 
 enum Enum { };
 



More information about the cfe-commits mailing list