Skip to content

[flang] Maybe fix an odd crash on AIX & SPARC #108271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

klausler
Copy link
Contributor

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

Experimental patch that avoids using a C++ reference after a
function call that may have invalidated it.
@klausler klausler requested review from rorth and kkwli September 11, 2024 18:47
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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

@kkwli
Copy link
Collaborator

kkwli commented Sep 11, 2024

The hang is still there on AIX.

@rorth
Copy link
Collaborator

rorth commented Sep 12, 2024

This made no difference on Solaris/sparcv9, unfortunately.

@klausler klausler closed this Sep 12, 2024
@klausler klausler deleted the fix-crash branch September 12, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants