[flang-commits] [flang] [Flang][OpenMP] Fix false positive common block error in LINEAR clause (PR #189170)

Aditya Trivedi via flang-commits flang-commits at lists.llvm.org
Sat Mar 28 22:07:14 PDT 2026


https://github.com/adit4443ya updated https://github.com/llvm/llvm-project/pull/189170

>From dd57afe1bcb3734dde71f07814f00b9ca316b255 Mon Sep 17 00:00:00 2001
From: Aditya Trivedi <adit4443ya at gmail.com>
Date: Sat, 28 Mar 2026 15:33:41 +0000
Subject: [PATCH] [Flang][OpenMP] Fix false positive common block error in
 LINEAR clause

The check for common block names in the OpenMP LINEAR clause previously
used FindCommonBlockContaining, which incorrectly flagged any variable
that was a member of a common block as violating the restriction that
a common block name cannot appear in a LINEAR clause.

This updates the check to correctly verify whether the symbol itself
has CommonBlockDetails.
---
 flang/lib/Semantics/check-omp-loop.cpp          | 4 ++--
 flang/test/Semantics/OpenMP/linear-clause01.f90 | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index e35e83e5b191b..dcae64aa54433 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -750,9 +750,9 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
           "The list item `%s` in a LINEAR clause must not be Cray Pointer or a variable with POINTER attribute"_err_en_US,
           symbol->name());
     }
-    if (FindCommonBlockContaining(*symbol)) {
+    if (symbol->has<CommonBlockDetails>()) {
       context_.Say(source,
-          "'%s' is a common block name and must not appear in an LINEAR clause"_err_en_US,
+          "'%s' is a common block name and must not appear in a LINEAR clause"_err_en_US,
           symbol->name());
     }
   }
diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index 63b09c07875e5..60a8ade1c954c 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -44,6 +44,5 @@ subroutine linear_clause_03(arg)
     integer :: i
     common /cc/ i
     !ERROR: The list item `i` must be a dummy argument
-    !ERROR: 'i' is a common block name and must not appear in an LINEAR clause
     !$omp declare simd linear(i)
 end subroutine linear_clause_03



More information about the flang-commits mailing list