@@ -2055,17 +2055,19 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2055
2055
// / Generate structured or unstructured FIR for an IF construct.
2056
2056
// / The initial statement may be either an IfStmt or an IfThenStmt.
2057
2057
void genFIR (const Fortran::parser::IfConstruct &) {
2058
- mlir::Location loc = toLocation ();
2059
2058
Fortran::lower::pft::Evaluation &eval = getEval ();
2059
+
2060
+ // Structured fir.if nest.
2060
2061
if (eval.lowerAsStructured ()) {
2061
- // Structured fir.if nest.
2062
2062
fir::IfOp topIfOp, currentIfOp;
2063
2063
for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations ()) {
2064
2064
auto genIfOp = [&](mlir::Value cond) {
2065
- auto ifOp = builder->create <fir::IfOp>(loc, cond, /* withElse=*/ true );
2065
+ auto ifOp =
2066
+ builder->create <fir::IfOp>(toLocation (), cond, /* withElse=*/ true );
2066
2067
builder->setInsertionPointToStart (&ifOp.getThenRegion ().front ());
2067
2068
return ifOp;
2068
2069
};
2070
+ setCurrentPosition (e.position );
2069
2071
if (auto *s = e.getIf <Fortran::parser::IfThenStmt>()) {
2070
2072
topIfOp = currentIfOp = genIfOp (genIfCondition (s, e.negateCondition ));
2071
2073
} else if (auto *s = e.getIf <Fortran::parser::IfStmt>()) {
@@ -2096,6 +2098,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2096
2098
else // non-empty block
2097
2099
genConditionalBranch (cond, e.lexicalSuccessor , e.controlSuccessor );
2098
2100
};
2101
+ setCurrentPosition (e.position );
2099
2102
if (auto *s = e.getIf <Fortran::parser::IfThenStmt>()) {
2100
2103
maybeStartBlock (e.block );
2101
2104
genIfBranch (genIfCondition (s, e.negateCondition ));
@@ -2863,6 +2866,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2863
2866
Fortran::lower::StatementContext stmtCtx;
2864
2867
pushActiveConstruct (eval, stmtCtx);
2865
2868
for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations ()) {
2869
+ setCurrentPosition (e.position );
2866
2870
if (auto *stmt = e.getIf <Fortran::parser::AssociateStmt>()) {
2867
2871
if (eval.lowerAsUnstructured ())
2868
2872
maybeStartBlock (e.block );
@@ -2891,10 +2895,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2891
2895
Fortran::lower::StatementContext stmtCtx;
2892
2896
pushActiveConstruct (eval, stmtCtx);
2893
2897
for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations ()) {
2898
+ setCurrentPosition (e.position );
2894
2899
if (e.getIf <Fortran::parser::BlockStmt>()) {
2895
2900
if (eval.lowerAsUnstructured ())
2896
2901
maybeStartBlock (e.block );
2897
- setCurrentPosition (e.position );
2898
2902
const Fortran::parser::CharBlock &endPosition =
2899
2903
eval.getLastNestedEvaluation ().position ;
2900
2904
localSymbols.pushScope ();
@@ -2921,7 +2925,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2921
2925
} else if (e.getIf <Fortran::parser::EndBlockStmt>()) {
2922
2926
if (eval.lowerAsUnstructured ())
2923
2927
maybeStartBlock (e.block );
2924
- setCurrentPosition (e.position );
2925
2928
localSymbols.popScope ();
2926
2929
} else {
2927
2930
genFIR (e);
@@ -2963,7 +2966,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2963
2966
}
2964
2967
2965
2968
void genFIR (const Fortran::parser::SelectTypeConstruct &selectTypeConstruct) {
2966
- mlir::Location loc = toLocation ();
2967
2969
mlir::MLIRContext *context = builder->getContext ();
2968
2970
Fortran::lower::StatementContext stmtCtx;
2969
2971
fir::ExtendedValue selector;
@@ -2989,6 +2991,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2989
2991
pushActiveConstruct (getEval (), stmtCtx);
2990
2992
for (Fortran::lower::pft::Evaluation &eval :
2991
2993
getEval ().getNestedEvaluations ()) {
2994
+ setCurrentPosition (eval.position );
2995
+ mlir::Location loc = toLocation ();
2992
2996
if (auto *selectTypeStmt =
2993
2997
eval.getIf <Fortran::parser::SelectTypeStmt>()) {
2994
2998
// A genFIR(SelectTypeStmt) call would have unwanted side effects.
0 commit comments