[flang-commits] [flang] 5096057 - [Flang][OpenMP] Fix crash when common block name is used in LINEAR clause (#203250)
via flang-commits
flang-commits at lists.llvm.org
Fri Jun 12 06:40:45 PDT 2026
Author: Aditya Trivedi
Date: 2026-06-12T08:40:41-05:00
New Revision: 5096057eb8254c7d56e1b70c4ba2fbf3ac215b73
URL: https://github.com/llvm/llvm-project/commit/5096057eb8254c7d56e1b70c4ba2fbf3ac215b73
DIFF: https://github.com/llvm/llvm-project/commit/5096057eb8254c7d56e1b70c4ba2fbf3ac215b73.diff
LOG: [Flang][OpenMP] Fix crash when common block name is used in LINEAR clause (#203250)
[Flang][OpenMP] Fix crash when common block name is used in LINEAR
clause
Using a common block name in a LINEAR clause (e.g. linear(/c/))
caused
a symbol-must-have-a-type crash during lowering. The semantic checker
was not emitting an error because GetSymbolsInObjectList expands /c/
to its member variables before the check runs, so the
symbol->has<CommonBlockDetails>() guard was never reached.
Fix by checking for common block names directly on the OmpObjectList
before the expansion, where the Name variant of OmpObject still holds
the common block symbol.
Fixes #202329
Added:
Modified:
flang/lib/Semantics/check-omp-structure.cpp
flang/test/Semantics/OpenMP/linear-clause01.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index e2a5ea66cac35..700e7df27efb3 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -671,11 +671,15 @@ void OmpStructureChecker::CheckArgumentObjectKind(const parser::OmpClause &x) {
// clauses. Assumed-size arrays are allowed on "map", "shared", and
// "use_device_addr". The check for this happens a few lines below.
bool AssumedSizeArrayAllowed{false};
+ bool CommonBlockAllowed{true};
bool NamedConstantAllowed{false};
switch (clauseId) {
case llvm::omp::Clause::OMPC_firstprivate:
NamedConstantAllowed = true;
break;
+ case llvm::omp::Clause::OMPC_linear:
+ CommonBlockAllowed = false;
+ break;
case llvm::omp::Clause::OMPC_map:
AssumedSizeArrayAllowed = true;
break;
@@ -708,6 +712,12 @@ void OmpStructureChecker::CheckArgumentObjectKind(const parser::OmpClause &x) {
parser::omp::GetUpperName(clauseId, version));
continue;
}
+ if (!CommonBlockAllowed && IsCommonBlock(*symbol)) {
+ context_.Say(source,
+ "'%s' is a common block name and must not appear in a %s clause"_err_en_US,
+ symbol->name(), parser::omp::GetUpperName(clauseId, version));
+ continue;
+ }
// Emit a more user-friendly diagnostic than "'kind' must be a variable
// list item" for x%kind, or for cplx%re.
if (IsTypeParamInquiry(*symbol)) {
diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index 7d3090e069a01..bb87b832d6aa9 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -46,6 +46,20 @@ subroutine linear_clause_03(arg)
!ERROR: The list item `i` must be a dummy argument
!$omp declare simd linear(i)
+ !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/)
end subroutine linear_clause_03
+
+! Case 4
+subroutine linear_clause_04(x)
+ real :: x(10)
+ integer :: b
+ common /c/ b
+ !ERROR: 'c' is a common block name and must not appear in a LINEAR clause
+ !$omp simd linear(/c/)
+ do i = 1, 10
+ x(i) = x(i) * 2
+ end do
+ !$omp end simd
+end subroutine linear_clause_04
More information about the flang-commits
mailing list