[Mlir-commits] [flang] [mlir] [Flang][OpenMP] Fix compilation error with integer(kind=8) in LINEAR clause. (PR #182474)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 20 03:12:18 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Urvi Rav (ravurvi20)

<details>
<summary>Changes</summary>

Fixes - [#<!-- -->178793](https://github.com/llvm/llvm-project/issues/178793)

This PR fixes a compilation error in Flang when using 8-byte integer constant for `linear-step` of `LINEAR clause`.

The current implementation in the OpenMP dialect restricted the linear step operand to `i32`. This patch updates `OpenMPClauses.td` to use `AnySignlessInteger`, allowing integer types of different widths (e.g., i32, i64, etc.) to be accepted.

Also, the existing testcase `simd-linear.f90` has also been updated to validate this behavior.

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


3 Files Affected:

- (modified) flang/test/Lower/OpenMP/simd-linear.f90 (+18) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+2-2) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+3-2) 


``````````diff
diff --git a/flang/test/Lower/OpenMP/simd-linear.f90 b/flang/test/Lower/OpenMP/simd-linear.f90
index 2caf1b0ad05fa..820bd4f98af71 100644
--- a/flang/test/Lower/OpenMP/simd-linear.f90
+++ b/flang/test/Lower/OpenMP/simd-linear.f90
@@ -80,3 +80,21 @@ subroutine linear_expr
     !CHECK: } {linear_var_types = [i32]}
     !IMPLICIT: } {linear_var_types = [i32, i32]}
 end subroutine
+
+subroutine simple_linear_i8
+  implicit none
+  integer(kind=8) :: x, y, i
+
+  ! CHECK-LABEL: func.func @_QPsimple_linear_i8
+
+  ! CHECK-DAG: %[[X_ALLOC:.*]] = fir.alloca i64 {bindc_name = "x"
+  ! CHECK: %[[C1_I32:.*]] = arith.constant 1 : i32
+
+  ! CHECK: omp.simd linear(%[[X_DECL:.*]]#0 = %[[C1_I32]] : !fir.ref<i64>) {{.*}}
+
+  !$omp simd linear(x)
+  do i = 1_8, 10_8
+  end do
+
+  ! CHECK: } {linear_var_types = [i64]}
+end subroutine
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
index ba52e52ebf58d..91826738e16d3 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
@@ -770,13 +770,13 @@ class OpenMP_LinearClauseSkip<
   > : OpenMP_Clause<traits, arguments, assemblyFormat, description,
                     extraClassDeclaration> {
   let arguments = (ins Variadic<AnyType>:$linear_vars,
-      Variadic<I32>:$linear_step_vars,
+      Variadic<AnySignlessInteger>:$linear_step_vars,
       OptionalAttr<ArrayAttr>:$linear_var_types);
 
   let optAssemblyFormat = [{
     `linear` `(`
       custom<LinearClause>($linear_vars, type($linear_vars),
-                           $linear_step_vars) `)`
+                           $linear_step_vars, type($linear_step_vars)) `)`
   }];
 
   let description = [{
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 601c970bc8a69..8c06342662ec5 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -423,7 +423,8 @@ static ParseResult parseLinearClause(
     OpAsmParser &parser,
     SmallVectorImpl<OpAsmParser::UnresolvedOperand> &linearVars,
     SmallVectorImpl<Type> &linearTypes,
-    SmallVectorImpl<OpAsmParser::UnresolvedOperand> &linearStepVars) {
+    SmallVectorImpl<OpAsmParser::UnresolvedOperand> &linearStepVars,
+    SmallVectorImpl<Type> &linearStepTypes) {
   return parser.parseCommaSeparatedList([&]() {
     OpAsmParser::UnresolvedOperand var;
     Type type;
@@ -442,7 +443,7 @@ static ParseResult parseLinearClause(
 /// Print Linear Clause
 static void printLinearClause(OpAsmPrinter &p, Operation *op,
                               ValueRange linearVars, TypeRange linearTypes,
-                              ValueRange linearStepVars) {
+                              ValueRange linearStepVars, TypeRange linearStepTypes) {
   size_t linearVarsSize = linearVars.size();
   for (unsigned i = 0; i < linearVarsSize; ++i) {
     std::string separator = i == linearVarsSize - 1 ? "" : ", ";

``````````

</details>


https://github.com/llvm/llvm-project/pull/182474


More information about the Mlir-commits mailing list