@@ -4734,6 +4734,105 @@ void x() {
47344734 EXPECT_TRUE (matchesWithOpenMP (Source8, Matcher));
47354735}
47364736
4737+ TEST_P (ASTMatchersTest, OMPTargetUpdateDirective_IsStandaloneDirective) {
4738+ auto Matcher = ompTargetUpdateDirective (isStandaloneDirective ());
4739+
4740+ StringRef Source0 = R"(
4741+ void foo() {
4742+ int arr[8];
4743+ #pragma omp target update from(arr[0:8:2])
4744+ ;
4745+ }
4746+ )" ;
4747+ EXPECT_TRUE (matchesWithOpenMP (Source0, Matcher));
4748+ }
4749+
4750+ TEST_P (ASTMatchersTest, OMPTargetUpdateDirective_HasStructuredBlock) {
4751+ StringRef Source0 = R"(
4752+ void foo() {
4753+ int arr[8];
4754+ #pragma omp target update from(arr[0:8:2])
4755+ ;
4756+ }
4757+ )" ;
4758+ EXPECT_TRUE (notMatchesWithOpenMP (
4759+ Source0, ompTargetUpdateDirective (hasStructuredBlock (nullStmt ()))));
4760+ }
4761+
4762+ TEST_P (ASTMatchersTest, OMPTargetUpdateDirective_HasClause) {
4763+ auto Matcher = ompTargetUpdateDirective (hasAnyClause (ompFromClause ()));
4764+
4765+ StringRef Source0 = R"(
4766+ void foo() {
4767+ int arr[8];
4768+ #pragma omp target update from(arr[0:8:2])
4769+ ;
4770+ }
4771+ )" ;
4772+ EXPECT_TRUE (matchesWithOpenMP (Source0, Matcher));
4773+
4774+ auto astUnit = tooling::buildASTFromCodeWithArgs (Source0, {" -fopenmp" });
4775+ ASSERT_TRUE (astUnit);
4776+
4777+ auto Results = match (ompTargetUpdateDirective ().bind (" directive" ),
4778+ astUnit->getASTContext ());
4779+ ASSERT_FALSE (Results.empty ());
4780+
4781+ const auto *Directive =
4782+ Results[0 ].getNodeAs <OMPTargetUpdateDirective>(" directive" );
4783+ ASSERT_TRUE (Directive);
4784+
4785+ OMPFromClause *FromClause = nullptr ;
4786+ for (auto *Clause : Directive->clauses ()) {
4787+ if (FromClause = dyn_cast<OMPFromClause>(Clause)) {
4788+ break ;
4789+ }
4790+ }
4791+ ASSERT_TRUE (FromClause);
4792+
4793+ for (const auto *VarExpr : FromClause->varlist ()) {
4794+ const auto *ArraySection = dyn_cast<ArraySectionExpr>(VarExpr);
4795+ if (!ArraySection)
4796+ continue ;
4797+ // base (arr)
4798+ const Expr *Base = ArraySection->getBase ();
4799+ ASSERT_TRUE (Base);
4800+
4801+ // lower bound (0)
4802+ const Expr *LowerBound = ArraySection->getLowerBound ();
4803+ ASSERT_TRUE (LowerBound);
4804+
4805+ // length (8)
4806+ const Expr *Length = ArraySection->getLength ();
4807+ ASSERT_TRUE (Length);
4808+
4809+ // stride (2)
4810+ const Expr *Stride = ArraySection->getStride ();
4811+ ASSERT_TRUE (Stride);
4812+ }
4813+ }
4814+
4815+ TEST_P (ASTMatchersTest, OMPTargetUpdateDirective_IsAllowedToContainClauseKind) {
4816+ auto Matcher = ompTargetUpdateDirective (
4817+ isAllowedToContainClauseKind (llvm::omp::OMPC_from));
4818+
4819+ StringRef Source0 = R"(
4820+ void x() {
4821+ ;
4822+ }
4823+ )" ;
4824+ EXPECT_TRUE (notMatchesWithOpenMP (Source0, Matcher));
4825+
4826+ StringRef Source1 = R"(
4827+ void foo() {
4828+ int arr[8];
4829+ #pragma omp target update from(arr[0:8:2])
4830+ ;
4831+ }
4832+ )" ;
4833+ EXPECT_TRUE (matchesWithOpenMP (Source1, Matcher));
4834+ }
4835+
47374836TEST_P (ASTMatchersTest, HasAnyBase_DirectBase) {
47384837 if (!GetParam ().isCXX ()) {
47394838 return ;
0 commit comments