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