File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -1732,7 +1732,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
17321732 Fortran::lower::SymbolBox resultSymBox = lookupSymbol (resultSym);
17331733 mlir::Location loc = toLocation ();
17341734 if (!resultSymBox) {
1735- mlir::emitError (loc, " internal error when processing function return" );
1735+ // Create a dummy undefined value of the expected return type.
1736+ // This prevents improper cleanup of StatementContext, which would lead
1737+ // to a crash due to a block with no terminator. See issue #126452.
1738+ mlir::FunctionType funcType = builder->getFunction ().getFunctionType ();
1739+ mlir::Type resultType = funcType.getResult (0 );
1740+ mlir::Value undefResult = builder->create <fir::UndefOp>(loc, resultType);
1741+ genExitRoutine (false , undefResult);
17361742 return ;
17371743 }
17381744 mlir::Value resultVal = resultSymBox.match (
Original file line number Diff line number Diff line change 1+ ! RUN: %flang -c %s -### 2>&1
2+ function s (x ) result(i)
3+ ! CHECK-WARNING: Function result is never defined
4+ integer :: x
5+ procedure ():: i
6+ end function
7+ end
You can’t perform that action at this time.
0 commit comments