Author: Zahira Ammarguellat Date: 2026-11-16T09:54:47-05:00 New Revision: 5a78ba27c71f49da21291828ef959f2bb35dbf5c
URL: https://github.com/llvm/llvm-project/commit/5a78ba27c71f49da21291828ef959f2bb35dbf5c DIFF: https://github.com/llvm/llvm-project/commit/5a78ba27c71f49da21291828ef959f2bb35dbf5c.diff LOG: [OpenMP] Allow dispatch when the call is replaced by a declare variant (#242482) A `dispatch` inside `parallel` was rejected when the base function also has a `construct={parallel}` variant. See https://godbolt.org/z/v9Gadhfsb. This patch: - adds `dispatch` to the construct context - looks through the `PseudoObjectExpr` to the original call when checking the dispatch statement. These two Sema changes were first made by @SunilKuravinakop in #131838, as part of the larger dispatch Sema and codegen work there. That PR has been inactive for a while, so this PR takes only the Sema fix for the rejected dispatch and adds a test for it. Added: clang/test/OpenMP/dispatch_variant_construct.c Modified: clang/lib/Sema/SemaOpenMP.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 257ee6e4d0389..24782f5a8c417 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -4861,6 +4861,8 @@ static void handleDeclareVariantConstructTrait(DSAStackTy *Stack, SmallVector<llvm::omp::TraitProperty, 8> Traits; if (isOpenMPTargetExecutionDirective(DKind)) Traits.emplace_back(llvm::omp::TraitProperty::construct_target_target); + if (DKind == OMPD_dispatch) + Traits.emplace_back(llvm::omp::TraitProperty::construct_dispatch_dispatch); if (isOpenMPTeamsDirective(DKind)) Traits.emplace_back(llvm::omp::TraitProperty::construct_teams_teams); if (isOpenMPParallelDirective(DKind)) @@ -11812,6 +11814,9 @@ StmtResult SemaOpenMP::ActOnOpenMPSectionDirective(Stmt *AStmt, static Expr *getDirectCallExpr(Expr *E) { E = E->IgnoreParenCasts()->IgnoreImplicit(); + // A call replaced by a declare variant keeps the original call. + if (auto *POE = dyn_cast<PseudoObjectExpr>(E)) + E = POE->getSyntacticForm()->IgnoreImpCasts(); if (auto *CE = dyn_cast<CallExpr>(E)) if (CE->getDirectCallee()) return E; diff --git a/clang/test/OpenMP/dispatch_variant_construct.c b/clang/test/OpenMP/dispatch_variant_construct.c new file mode 100644 index 0000000000000..02c3dcd4ecd0e --- /dev/null +++ b/clang/test/OpenMP/dispatch_variant_construct.c @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -ast-dump %s | FileCheck %s + +// expected-no-diagnostics + +// The call under dispatch can be replaced by a variant that matches the +// dispatch construct. + +void f_par(void) {} +void f_par_dispatch(void) {} + +#pragma omp declare variant(f_par) match(construct = {parallel}) +#pragma omp declare variant(f_par_dispatch) \ + match(construct = {parallel, dispatch}) +void f(void) {} + +void g_dispatch(void) {} + +#pragma omp declare variant(g_dispatch) match(construct = {dispatch}) +void g(void) {} + +// CHECK-LABEL: FunctionDecl {{.*}} test_parallel +// CHECK: OMPDispatchDirective +// CHECK: PseudoObjectExpr +// CHECK: DeclRefExpr {{.*}} 'f' 'void (void)' +// CHECK: DeclRefExpr {{.*}} 'f_par_dispatch' 'void (void)' +void test_parallel(void) { +#pragma omp parallel + { +#pragma omp dispatch + f(); + } +} + +// CHECK-LABEL: FunctionDecl {{.*}} test_top_level +// CHECK: OMPDispatchDirective +// CHECK: PseudoObjectExpr +// CHECK: DeclRefExpr {{.*}} 'g' 'void (void)' +// CHECK: DeclRefExpr {{.*}} 'g_dispatch' 'void (void)' +void test_top_level(void) { +#pragma omp dispatch + g(); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
