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

via flang-commits flang-commits at lists.llvm.org
Thu Nov 30 05:51:19 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Sergio Afonso (skatrak)

<details>
<summary>Changes</summary>

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.

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


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+1-1) 
- (added) flang/test/Semantics/OpenMP/struct.f90 (+7) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index da6c865ad56a3b1..9084bffc7139869 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -25,7 +25,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 000000000000000..8ae1fbe4da86f93
--- /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

``````````

</details>


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


More information about the flang-commits mailing list