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 {
1732
1732
Fortran::lower::SymbolBox resultSymBox = lookupSymbol (resultSym);
1733
1733
mlir::Location loc = toLocation ();
1734
1734
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);
1736
1742
return ;
1737
1743
}
1738
1744
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