Skip to content

Conversation

@amitamd7
Copy link
Contributor

@amitamd7 amitamd7 commented Jul 25, 2025

Added support for detecting OMPTargetUpdateDirective , OMPFromClause and OMPToClause in Clang Unit Test Framework

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category offload labels Jul 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-offload

@llvm/pr-subscribers-clang

Author: Amit Tiwari (amitamd7)

Changes

Added support for detecting OMP Target Directive and OMP From Clause in Clang Unit Test Framework


Full diff: https://github.com/llvm/llvm-project/pull/150580.diff

4 Files Affected:

  • (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+27)
  • (modified) clang/lib/ASTMatchers/ASTMatchersInternal.cpp (+4)
  • (modified) clang/lib/ASTMatchers/Dynamic/Registry.cpp (+2)
  • (added) offload/test/offloading/strided_update.c (+50)
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 08c898f7758ec..5ca075528add5 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -8735,6 +8735,21 @@ AST_MATCHER_P(OMPExecutableDirective, hasAnyClause,
                                     Builder) != Clauses.end();
 }
 
+/// Matches any ``#pragma omp target update`` executable directive.
+///
+/// Given
+///
+/// \code
+///   #pragma omp target update from(a)
+///   #pragma omp target update to(b)
+/// \endcode
+///
+/// ``ompTargetUpdateDirective()`` matches both ``omp target update from(a)``
+/// and ``omp target update to(b)``.
+extern const internal::VariadicDynCastAllOfMatcher<Stmt,
+                                                   OMPTargetUpdateDirective>
+    ompTargetUpdateDirective;
+
 /// Matches OpenMP ``default`` clause.
 ///
 /// Given
@@ -8848,6 +8863,18 @@ AST_MATCHER_P(OMPExecutableDirective, isAllowedToContainClauseKind,
       Finder->getASTContext().getLangOpts().OpenMP);
 }
 
+/// Matches OpenMP ``from`` clause.
+///
+/// Given
+///
+/// \code
+///   #pragma omp target update from(a)
+/// \endcode
+///
+/// ``ompFromClause()`` matches ``from(a)``.
+extern const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPFromClause>
+    ompFromClause;
+
 //----------------------------------------------------------------------------//
 // End OpenMP handling.
 //----------------------------------------------------------------------------//
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 80dc888811657..7580cee3d8aed 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1125,8 +1125,12 @@ AST_TYPELOC_TRAVERSE_MATCHER_DEF(
 
 const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective>
     ompExecutableDirective;
+const internal::VariadicDynCastAllOfMatcher<Stmt, OMPTargetUpdateDirective>
+    ompTargetUpdateDirective;
 const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause>
     ompDefaultClause;
+const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPFromClause>
+    ompFromClause;
 const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl>
     cxxDeductionGuideDecl;
 
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 562df715e08ae..e74fae3c50029 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -531,7 +531,9 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(ofClass);
   REGISTER_MATCHER(ofKind);
   REGISTER_MATCHER(ompDefaultClause);
+  REGISTER_MATCHER(ompFromClause);
   REGISTER_MATCHER(ompExecutableDirective);
+  REGISTER_MATCHER(ompTargetUpdateDirective);
   REGISTER_MATCHER(on);
   REGISTER_MATCHER(onImplicitObjectArgument);
   REGISTER_MATCHER(opaqueValueExpr);
diff --git a/offload/test/offloading/strided_update.c b/offload/test/offloading/strided_update.c
new file mode 100644
index 0000000000000..271a00de5f7a1
--- /dev/null
+++ b/offload/test/offloading/strided_update.c
@@ -0,0 +1,50 @@
+// Checks that "update from" clause in OpenMP is supported when the elements are updated in a non-contiguous manner.
+// RUN: %libomptarget-compile-run-and-check-generic
+#include <omp.h>  
+#include <stdio.h>  
+  
+int main() {  
+  int len = 8;  
+  double data[len];  
+  #pragma omp target map(tofrom: len, data[0:len])  
+  {  
+    for (int i = 0; i < len; i++) {  
+      data[i] = i;  
+    }  
+  }  
+  // initial values  
+  printf("original host array values:\n");  
+  for (int i = 0; i < len; i++)  
+    printf("%f\n", data[i]);  
+  printf("\n");  
+  
+  #pragma omp target data map(to: len, data[0:len])  
+  {  
+    #pragma omp target  
+    for (int i = 0; i < len; i++) {  
+      data[i] += i ;  
+    }  
+  
+    #pragma omp target update from(data[0:8:2])  
+  }  
+  // from results  
+  // CHECK: 0.000000
+  // CHECK: 1.000000
+  // CHECK: 4.000000
+  // CHECK: 3.000000
+  // CHECK: 8.000000
+  // CHECK: 5.000000
+  // CHECK: 12.000000
+  // CHECK: 7.000000
+  // CHECK-NOT: 2.000000
+  // CHECK-NOT: 6.000000
+  // CHECK-NOT: 10.000000
+  // CHECK-NOT: 14.000000
+
+  printf("from target array results:\n");  
+  for (int i = 0; i < len; i++)  
+    printf("%f\n", data[i]);  
+  printf("\n");  
+  
+  return 0;  
+}  

@github-actions
Copy link

github-actions bot commented Jul 25, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@amitamd7 amitamd7 force-pushed the tiwari_support_target_directive_clang_unittest branch from 85653b4 to 4b0be55 Compare July 25, 2025 09:17
@amitamd7 amitamd7 changed the title [Clang][Unittest] Support for target directive and from clause in clang unittests [Clang][Unittest] Support for target update directive and from clause in clang unittests Jul 25, 2025
Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem to be tested?

@amitamd7 amitamd7 force-pushed the tiwari_support_target_directive_clang_unittest branch 2 times, most recently from d7d3652 to 615209b Compare July 28, 2025 11:49
@amitamd7
Copy link
Contributor Author

it doesn't seem to be tested?

I have added them now.

@saiislam saiislam requested a review from alexey-bataev July 29, 2025 10:05
@amitamd7 amitamd7 force-pushed the tiwari_support_target_directive_clang_unittest branch from 615209b to 8d64264 Compare September 2, 2025 11:50
@amitamd7
Copy link
Contributor Author

amitamd7 commented Sep 2, 2025

Ping.

@amitamd7 amitamd7 requested a review from shiltian September 4, 2025 11:09
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test the variadic part, aka. more items in the from clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated the patch with refined checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@amitamd7 amitamd7 force-pushed the tiwari_support_target_directive_clang_unittest branch 2 times, most recently from 82a7bd0 to d536696 Compare September 10, 2025 06:20
@amitamd7 amitamd7 marked this pull request as draft November 26, 2025 08:40
@amitamd7 amitamd7 force-pushed the tiwari_support_target_directive_clang_unittest branch from d536696 to a7a8256 Compare November 26, 2025 08:40
@amitamd7 amitamd7 marked this pull request as ready for review November 26, 2025 15:51
@amitamd7
Copy link
Contributor Author

@shiltian can you please approve this one if it looks suitable?

@amitamd7 amitamd7 marked this pull request as draft December 4, 2025 12:22
@amitamd7
Copy link
Contributor Author

amitamd7 commented Dec 5, 2025

Added here update to clause changes too as creating separate PR for this won't make much sense.

@amitamd7 amitamd7 force-pushed the tiwari_support_target_directive_clang_unittest branch from cf55536 to b60f187 Compare December 5, 2025 07:59
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

🐧 Linux x64 Test Results

  • 91758 tests passed
  • 2462 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

RealtimeSanitizer-Unit

RealtimeSanitizer-Unit._/Rtsan-x86_64-FileOffset64-Test/RtsanFileTest/OpenCreatesFileWithProperMode
Script:
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/runtimes/runtimes-bins/compiler-rt/lib/rtsan/tests/./Rtsan-x86_64-FileOffset64-Test --gtest_filter=RtsanFileTest.OpenCreatesFileWithProperMode
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp:440
Value of: stat(GetTemporaryFilePath(), &st)
Expected: is equal to 0
  Actual: -1


If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category offload

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants