From 2cc5b8ca55a1834e29dbde932ac8f93bc43cc6da Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sun, 18 Oct 2026 11:58:47 -0500 Subject: [PATCH] =?UTF-8?q?[flang][OpenMP]=20Ignore=20DECLARE=5FSIMD=20and?= =?UTF-8?q?=20warn=20about=20missing=20implementa=E2=80=A6=20(#232712)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …tion Currently DECLARE_SIMD emits a "not yet implemented" error in the MLIR to LLVM IR translation. DECLARE_SIMD is a hint to the compiler and ignoring it is technically speaking a conforming implementation (although obviously not desirable). Do not abort compilation when DECLARE_SIMD is encountered, but emit a warning that it's currently ignored. (cherry picked from commit 5ca62fdee645ec253263e41a45fe626c6b66be22) Fixes: https://github.com/llvm/llvm-project/issues/234108 --- flang/lib/Semantics/check-omp-structure.cpp | 5 +++++ flang/test/Semantics/OpenMP/cray-pointer-usage.f90 | 1 + flang/test/Semantics/OpenMP/declarative-directive01.f90 | 2 ++ flang/test/Semantics/OpenMP/declare-simd-empty.f90 | 3 ++- .../test/Semantics/OpenMP/declare-simd-interface-body.f90 | 6 +++++- flang/test/Semantics/OpenMP/declare-simd-uniform.f90 | 2 ++ flang/test/Semantics/OpenMP/declare-simd.f90 | 6 +++++- flang/test/Semantics/OpenMP/future-directive-spellings.f90 | 1 + flang/test/Semantics/OpenMP/linear-clause01.f90 | 6 ++++++ flang/test/Semantics/OpenMP/linear-clause02.f90 | 2 ++ flang/test/Semantics/OpenMP/linear-clause03.f90 | 1 + flang/test/Semantics/OpenMP/simd-linear-array.f90 | 1 + .../LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 7 +++++++ 13 files changed, 40 insertions(+), 3 deletions(-) diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 68d7a166be0f..37ad95538288 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -1928,6 +1928,11 @@ void OmpStructureChecker::Leave(const parser::OmpThreadprivateDirective &x) { void OmpStructureChecker::Enter(const parser::OmpDeclareSimdDirective &x) { const parser::OmpDirectiveName &dirName{x.v.DirName()}; + unsigned version{context_.langOptions().OpenMPVersion}; + context_.Say(dirName.source, + "%s directive is not implemented yet and will be ignored"_warn_en_US, + GetUpperName(dirName.v, version)); + const Scope &containingScope = context_.FindScope(dirName.source); const Scope &progUnitScope = GetProgramUnitContaining(containingScope); diff --git a/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 index 025d339ec817..8a1b1f0ec90e 100644 --- a/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 +++ b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 @@ -4,6 +4,7 @@ subroutine test_cray_pointer_usage integer :: i real(8) :: var(*), pointee(2) pointer(ivar, var) + ! WARNING: DECLARE SIMD directive is not implemented yet and will be ignored ! ERROR: Cray Pointee 'var' may not appear in LINEAR clause ! ERROR: List item 'var' in LINEAR clause must be a scalar variable ! ERROR: The list item 'var' specified without the REF 'linear-modifier' must be of INTEGER type diff --git a/flang/test/Semantics/OpenMP/declarative-directive01.f90 b/flang/test/Semantics/OpenMP/declarative-directive01.f90 index 136b855ba7b4..bc60e2e2f7c0 100644 --- a/flang/test/Semantics/OpenMP/declarative-directive01.f90 +++ b/flang/test/Semantics/OpenMP/declarative-directive01.f90 @@ -21,6 +21,7 @@ end subroutine requires_2 subroutine declare_simd_1(a, b) real(8), intent(inout) :: a, b + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !ERROR: 'a' in ALIGNED clause must be of type C_PTR, POINTER or ALLOCATABLE !$omp declare simd(declare_simd_1) aligned(a) a = 3.14 + b @@ -38,6 +39,7 @@ end module m1 subroutine declare_simd_2 use m1 procedure (sub) sub1 + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !ERROR: INBRANCH and NOTINBRANCH clauses are mutually exclusive and may not appear on the same DECLARE SIMD directive !$omp declare simd(sub1) inbranch notinbranch procedure (sub), pointer::p diff --git a/flang/test/Semantics/OpenMP/declare-simd-empty.f90 b/flang/test/Semantics/OpenMP/declare-simd-empty.f90 index b61fb53730a2..19d109631d12 100644 --- a/flang/test/Semantics/OpenMP/declare-simd-empty.f90 +++ b/flang/test/Semantics/OpenMP/declare-simd-empty.f90 @@ -1,6 +1,7 @@ -! RUN: %python %S/../test_errors.py %s %flang -fopenmp +! RUN: %python %S/../test_errors.py %s %flang -fopenmp -Werror -Wno-experimental-option ! Test the source code starting with omp syntax +!WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd integer :: x end diff --git a/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90 b/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90 index 624afa8852f2..7a8553be4121 100644 --- a/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90 +++ b/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90 @@ -6,12 +6,14 @@ interface subroutine add2(i) + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage] !$omp declare simd(add2) linear(i:1) integer :: i end subroutine subroutine add3(i) + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage] !$omp declare simd integer :: i @@ -20,8 +22,10 @@ end interface contains -! A DECLARE SIMD in an actual definition is fine and must not warn. +! A DECLARE SIMD in an actual definition is fine and must not warn about +! its effect. subroutine sub(i) +!WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd(sub) linear(i:1) integer :: i i = i + 1 diff --git a/flang/test/Semantics/OpenMP/declare-simd-uniform.f90 b/flang/test/Semantics/OpenMP/declare-simd-uniform.f90 index 1ca18a98976e..f63892c8fb99 100644 --- a/flang/test/Semantics/OpenMP/declare-simd-uniform.f90 +++ b/flang/test/Semantics/OpenMP/declare-simd-uniform.f90 @@ -3,6 +3,7 @@ ! Test declare simd with uniform clause function add2(a,b,i,fact,alc) result(c) + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd(add2) uniform(a,b,fact) integer :: i integer,pointer::alc @@ -27,6 +28,7 @@ function bad_uniform(a,b,i) result(c) double precision :: a(*), b(*), c integer :: i double precision :: local + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !ERROR: Variable 'local' in UNIFORM clause must be a dummy argument of the enclosing procedure !$omp declare simd(bad_uniform) uniform(a,local) c = a(i) + b(i) + local diff --git a/flang/test/Semantics/OpenMP/declare-simd.f90 b/flang/test/Semantics/OpenMP/declare-simd.f90 index bb259b8722ca..a8f0e2a462d5 100644 --- a/flang/test/Semantics/OpenMP/declare-simd.f90 +++ b/flang/test/Semantics/OpenMP/declare-simd.f90 @@ -2,12 +2,15 @@ module m +!WARNING: DECLARE_SIMD directive is not implemented yet and will be ignored !ERROR: The name 'x' should refer to a procedure !$omp declare_simd(x) +!WARNING: DECLARE_SIMD directive is not implemented yet and will be ignored !ERROR: DECLARE_SIMD directive should have at most one argument !$omp declare_simd(f00, f01) +!WARNING: DECLARE_SIMD directive is not implemented yet and will be ignored !ERROR: The argument to the DECLARE_SIMD directive should be a procedure name !$omp declare_simd(v : integer) @@ -20,7 +23,8 @@ subroutine f01 end integer function f02 -!Ok, expect no diagnostics +!Ok, expect no errors +!WARNING: DECLARE_SIMD directive is not implemented yet and will be ignored !$omp declare_simd(f02) end diff --git a/flang/test/Semantics/OpenMP/future-directive-spellings.f90 b/flang/test/Semantics/OpenMP/future-directive-spellings.f90 index b7705ddd95c4..8445bef52ebb 100644 --- a/flang/test/Semantics/OpenMP/future-directive-spellings.f90 +++ b/flang/test/Semantics/OpenMP/future-directive-spellings.f90 @@ -41,6 +41,7 @@ subroutine f02 end subroutine f03 +!WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !WARNING: Directive spelling 'DECLARE_SIMD' is introduced in a later OpenMP version, try -fopenmp-version=60 !$omp declare_simd end diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90 index bb87b832d6aa..db58f5565404 100644 --- a/flang/test/Semantics/OpenMP/linear-clause01.f90 +++ b/flang/test/Semantics/OpenMP/linear-clause01.f90 @@ -19,16 +19,19 @@ end subroutine linear_clause_01 subroutine linear_clause_02(arg_01, arg_02) !ERROR: The list item 'arg_01' specified without the REF 'linear-modifier' must be of INTEGER type !ERROR: List item 'arg_01' in LINEAR clause must be a scalar variable + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd linear(val(arg_01)) real, intent(in) :: arg_01(:) !ERROR: If the `linear-modifier` is REF or UVAL, the list item 'arg_02' must be a dummy argument without the VALUE attribute + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd linear(uval(arg_02)) integer, value, intent(in) :: arg_02 !ERROR: If the `linear-modifier` is REF or UVAL, the list item 'var' must be a dummy argument without the VALUE attribute !ERROR: The list item `var` must be a dummy argument !ERROR: The list item `var` in a LINEAR clause must not be Cray Pointer or a variable with POINTER attribute + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd linear(uval(var)) integer, pointer :: var end subroutine linear_clause_02 @@ -39,13 +42,16 @@ subroutine linear_clause_03(arg) !ERROR: The list item `arg` specified with the REF 'linear-modifier' must be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute !ERROR: List item 'arg' present at multiple LINEAR clauses !ERROR: 'arg' appears in more than one data-sharing clause on the same OpenMP directive + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd linear(ref(arg)) linear(arg) integer :: i common /cc/ i + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !ERROR: The list item `i` must be a dummy argument !$omp declare simd linear(i) + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !ERROR: 'cc' is a common block name and must not appear in a LINEAR clause !ERROR: The list item `i` must be a dummy argument !$omp declare simd linear(/cc/) diff --git a/flang/test/Semantics/OpenMP/linear-clause02.f90 b/flang/test/Semantics/OpenMP/linear-clause02.f90 index 695d61715820..ff002b973541 100644 --- a/flang/test/Semantics/OpenMP/linear-clause02.f90 +++ b/flang/test/Semantics/OpenMP/linear-clause02.f90 @@ -3,11 +3,13 @@ subroutine f00(x) integer :: x !WARNING: The 'modifier()' syntax is deprecated in OpenMP v5.2, use ' : modifier' instead + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd linear(uval(x)) end subroutine f01(x) integer :: x + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !ERROR: An exclusive 'step-simple-modifier' modifier cannot be specified together with a modifier of a different type !$omp declare simd linear(uval(x) : 2) end diff --git a/flang/test/Semantics/OpenMP/linear-clause03.f90 b/flang/test/Semantics/OpenMP/linear-clause03.f90 index 3c89f2e93b4a..5f52412dc2c6 100644 --- a/flang/test/Semantics/OpenMP/linear-clause03.f90 +++ b/flang/test/Semantics/OpenMP/linear-clause03.f90 @@ -6,6 +6,7 @@ interface subroutine f(x, y) integer, allocatable :: x integer :: y + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage] !$omp declare simd(f) linear(ref(x) : 1) linear(uval(y)) end diff --git a/flang/test/Semantics/OpenMP/simd-linear-array.f90 b/flang/test/Semantics/OpenMP/simd-linear-array.f90 index e904f348ae47..c9a8ede04123 100644 --- a/flang/test/Semantics/OpenMP/simd-linear-array.f90 +++ b/flang/test/Semantics/OpenMP/simd-linear-array.f90 @@ -75,6 +75,7 @@ subroutine test_declare_simd_ref_array_valid(arr) implicit none integer, intent(in) :: arr(:) + !WARNING: DECLARE SIMD directive is not implemented yet and will be ignored !$omp declare simd linear(ref(arr)) ! No error expected - REF modifier allows assumed-shape arrays end subroutine diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 7bb15b74aeac..9598932753a4 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -9743,6 +9743,13 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation( .Case([&](omp::GroupprivateOp) { return convertOmpGroupprivate(*op, builder, moduleTranslation); }) + .Case([&](omp::DeclareSimdOp) { + // TODO: Implement. + // DECLARE_SIMD can be ignored. There is warning emitted in + // semantic checks about the current situation, but not having an + // implementation should not prevent compilation. + return success(); + }) .Default([&](Operation *inst) { return inst->emitError() << "not yet implemented: " << inst->getName();