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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Sep 11 11:47:40 PDT 2024


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

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

>From 90d9b94b0c2ce42c2bffb3bcc585aec1ebd6ceaa Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 11 Sep 2024 11:45:55 -0700
Subject: [PATCH] [flang] Maybe fix an odd crash on AIX & SPARC

Experimental patch that avoids using a C++ reference after a
function call that may have invalidated it.
---
 flang/lib/Semantics/expression.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

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_) {



More information about the flang-commits mailing list