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

via flang-commits flang-commits at lists.llvm.org
Thu Feb 22 06:35:08 PST 2024


Author: Sergio Afonso
Date: 2024-02-22T14:35:05Z
New Revision: 27498e9942dbb8dd005588a03d6777088d2255ce

URL: https://github.com/llvm/llvm-project/commit/27498e9942dbb8dd005588a03d6777088d2255ce
DIFF: https://github.com/llvm/llvm-project/commit/27498e9942dbb8dd005588a03d6777088d2255ce.diff

LOG: [Flang][OpenMP] Prevent ICE for certain constructs in unnamed programs (#73938)

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
a nameless program, which can sometimes not be associated to any scope,
causing an ICE due to an invalid source location.

Added: 
    flang/test/Semantics/OpenMP/struct.f90

Modified: 
    flang/lib/Semantics/resolve-directives.cpp

Removed: 
    


################################################################################
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