Skip to content

Conversation

@kparzysz
Copy link
Contributor

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Oct 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

This fixes https://linaro.atlassian.net/browse/LLVM-2106.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+1-1)
  • (added) flang/test/Semantics/OpenMP/anonymous-block-data.f90 (+11)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 41416304c1ea6..e094458f001e3 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -98,7 +98,7 @@ bool OmpStructureChecker::Enter(const parser::BlockData &x) {
   } else {
     for (const Scope &scope : context_.globalScope().children()) {
       if (scope.kind() == Scope::Kind::BlockData) {
-        if (scope.symbol()->name().empty()) {
+        if (auto *s{scope.symbol()}; !s || s->name().empty()) {
           scopeStack_.push_back(&scope);
           break;
         }
diff --git a/flang/test/Semantics/OpenMP/anonymous-block-data.f90 b/flang/test/Semantics/OpenMP/anonymous-block-data.f90
new file mode 100644
index 0000000000000..129a95f9f5621
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/anonymous-block-data.f90
@@ -0,0 +1,11 @@
+!RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s
+
+! To trigger the crash, -fsyntax-only was sufficient, but when everything
+! is correct, it won't produce any output. To get something to check on
+! success, run unparse, which does run semantic checks.
+
+block data
+end
+
+!CHECK: BLOCK DATA
+!CHECK: END BLOCK DATA

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-flang-semantics

Author: Krzysztof Parzyszek (kparzysz)

Changes

This fixes https://linaro.atlassian.net/browse/LLVM-2106.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-omp-structure.cpp (+1-1)
  • (added) flang/test/Semantics/OpenMP/anonymous-block-data.f90 (+11)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 41416304c1ea6..e094458f001e3 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -98,7 +98,7 @@ bool OmpStructureChecker::Enter(const parser::BlockData &x) {
   } else {
     for (const Scope &scope : context_.globalScope().children()) {
       if (scope.kind() == Scope::Kind::BlockData) {
-        if (scope.symbol()->name().empty()) {
+        if (auto *s{scope.symbol()}; !s || s->name().empty()) {
           scopeStack_.push_back(&scope);
           break;
         }
diff --git a/flang/test/Semantics/OpenMP/anonymous-block-data.f90 b/flang/test/Semantics/OpenMP/anonymous-block-data.f90
new file mode 100644
index 0000000000000..129a95f9f5621
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/anonymous-block-data.f90
@@ -0,0 +1,11 @@
+!RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s
+
+! To trigger the crash, -fsyntax-only was sufficient, but when everything
+! is correct, it won't produce any output. To get something to check on
+! success, run unparse, which does run semantic checks.
+
+block data
+end
+
+!CHECK: BLOCK DATA
+!CHECK: END BLOCK DATA

@eugeneepshteyn
Copy link
Contributor

This also fixes #164815

Copy link
Contributor

@eugeneepshteyn eugeneepshteyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kparzysz kparzysz merged commit 48cc443 into main Oct 27, 2025
14 checks passed
@kparzysz kparzysz deleted the users/kparzysz/fujitsu-fix branch October 27, 2025 14:50
@s-watanabe314
Copy link
Contributor

Our latest tests have confirmed that all regressions detected in https://linaro.atlassian.net/browse/LLVM-2106 have been resolved. Thank you for the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:openmp flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants