[flang-commits] [flang] [flang] Fix crash in semantics on bad program (PR #87199)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sun Mar 31 11:48:35 PDT 2024


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

Don't accept a putative statement function definition for a symbol that is a subprogram but can't possibly be a statement function.

Fixes https://github.com/llvm/llvm-project/issues/86936.

>From c210cb3850bc2493be4aaedc07c7cc5ef58d4cc7 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Sun, 31 Mar 2024 11:46:10 -0700
Subject: [PATCH] [flang] Fix crash in semantics on bad program

Don't accept a putative statement function definition for a symbol
that is a subprogram but can't possibly be a statement function.

Fixes https://github.com/llvm/llvm-project/issues/86936.
---
 flang/lib/Semantics/resolve-names.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 2e88a2daff2c08..f2db329e30be78 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8525,7 +8525,9 @@ void ResolveNamesVisitor::AnalyzeStmtFunctionStmt(
   Symbol *symbol{name.symbol};
   auto *details{symbol ? symbol->detailsIf<SubprogramDetails>() : nullptr};
   if (!details || !symbol->scope() ||
-      &symbol->scope()->parent() != &currScope()) {
+      &symbol->scope()->parent() != &currScope() || details->isInterface() ||
+      details->isDummy() || details->entryScope() ||
+      details->moduleInterface() || symbol->test(Symbol::Flag::Subroutine)) {
     return; // error recovery
   }
   // Resolve the symbols on the RHS of the statement function.



More information about the flang-commits mailing list