[flang-commits] [flang] [Flang][OpenMP] Prevent ICE for certain constructs in unnamed programs (PR #73938)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Thu Feb 22 05:52:17 PST 2024


https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/73938

>From 728d2853f1c035f8b8442d5a67dec57b4dcdfd8c Mon Sep 17 00:00:00 2001
From: Sergio Afonso <safonsof at amd.com>
Date: Thu, 30 Nov 2023 13:12:39 +0000
Subject: [PATCH] [Flang][OpenMP] Prevent ICE for certain constructs in unnamed
 programs

This patch fixes #72748 by modifying the processing of program units to search
for a symbol to which OpenMP REQUIRES clauses can bind to. Rather than picking
up the first PFT node with a source reference and getting its associated scope,
it picks up the last one.

This avoids using the source from the first specification construct of an
nameless program, which can sometimes not be associated to any scope, causing
an ICE due to an invalid source location.
---
 flang/lib/Semantics/resolve-directives.cpp | 2 +-
 flang/test/Semantics/OpenMP/struct.f90     | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/OpenMP/struct.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index a826f0181e580c..215a3c9060a241 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -26,7 +26,7 @@
 template <typename T>
 static Fortran::semantics::Scope *GetScope(
     Fortran::semantics::SemanticsContext &context, const T &x) {
-  std::optional<Fortran::parser::CharBlock> source{GetSource(x)};
+  std::optional<Fortran::parser::CharBlock> source{GetLastSource(x)};
   return source ? &context.FindScope(*source) : nullptr;
 }
 
diff --git a/flang/test/Semantics/OpenMP/struct.f90 b/flang/test/Semantics/OpenMP/struct.f90
new file mode 100644
index 00000000000000..8ae1fbe4da86f9
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/struct.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+! Check OpenMP compatibility with the DEC STRUCTURE extension
+
+structure /s/
+end structure
+
+end



More information about the flang-commits mailing list