[flang-commits] [flang] [flang] Maybe fix an odd crash on AIX & SPARC (PR #108271)

via flang-commits flang-commits at lists.llvm.org
Wed Sep 11 11:48:12 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

Experimental patch that avoids using a C++ reference after a function call that may have invalidated it.

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


1 Files Affected:

- (modified) flang/lib/Semantics/expression.cpp (+8-3) 


``````````diff
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 943512f75d7eba..636e0dd1dbccc2 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2667,9 +2667,12 @@ const Symbol *ExpressionAnalyzer::ResolveForward(const Symbol &symbol) {
       // procedure.  Resolve its names now so that its interface
       // is known.
       const semantics::Scope &scope{symbol.owner()};
+      // Save the name, since "symbol" may vanish.
+      std::string name{symbol.name().ToString()};
       semantics::ResolveSpecificationParts(context_, symbol);
       const Symbol *resolved{nullptr};
-      if (auto iter{scope.find(symbol.name())}; iter != scope.cend()) {
+      if (auto iter{scope.find(parser::CharBlock{name})};
+          iter != scope.cend()) {
         resolved = &*iter->second;
       }
       if (!resolved || resolved->has<semantics::SubprogramNameDetails>()) {
@@ -2678,8 +2681,10 @@ const Symbol *ExpressionAnalyzer::ResolveForward(const Symbol &symbol) {
         // specification part; but recursive function calls are not
         // allowed in specification parts (10.1.11 para 5).
         Say("The module function '%s' may not be referenced recursively in a specification expression"_err_en_US,
-            symbol.name());
-        context_.SetError(symbol);
+            name);
+        if (resolved) {
+          context_.SetError(*resolved);
+        }
       }
       return resolved;
     } else if (inStmtFunctionDefinition_) {

``````````

</details>


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


More information about the flang-commits mailing list