@@ -1157,6 +1157,12 @@ class FirConverter : public Fortran::lower::AbstractConverter {
11571157 return registeredDummySymbols.contains (sym);
11581158 }
11591159
1160+ unsigned getDummyArgPosition (
1161+ const Fortran::semantics::Symbol &sym) const override final {
1162+ auto it = dummyArgPositions.find (&sym);
1163+ return (it != dummyArgPositions.end ()) ? it->second : 0 ;
1164+ }
1165+
11601166 const Fortran::lower::pft::FunctionLikeUnit *
11611167 getCurrentFunctionUnit () const override final {
11621168 return currentFunctionUnit;
@@ -1441,11 +1447,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
14411447 // / definitive mapping. The specification expression have not been lowered
14421448 // / yet. The final mapping will be done using this pre-mapping in
14431449 // / Fortran::lower::mapSymbolAttributes.
1450+ // / \param argNo The 1-based source position of this argument (0 if
1451+ // / unknown/result)
14441452 bool mapBlockArgToDummyOrResult (const Fortran::semantics::SymbolRef sym,
1445- mlir::Value val, bool isResult) {
1453+ mlir::Value val, bool isResult,
1454+ unsigned argNo = 0 ) {
14461455 localSymbols.addSymbol (sym, val);
14471456 if (!isResult)
1448- registerDummySymbol (sym);
1457+ registerDummySymbol (sym, argNo );
14491458
14501459 return true ;
14511460 }
@@ -6007,7 +6016,16 @@ class FirConverter : public Fortran::lower::AbstractConverter {
60076016 const Fortran::lower::CalleeInterface &callee) {
60086017 assert (builder && " require a builder object at this point" );
60096018 using PassBy = Fortran::lower::CalleeInterface::PassEntityBy;
6019+
6020+ // Track the source-level argument position (1-based)
6021+ unsigned argPosition = 0 ;
6022+
60106023 auto mapPassedEntity = [&](const auto arg, bool isResult = false ) {
6024+ // Count only actual source-level dummy arguments (not results or
6025+ // host assoc tuples)
6026+ if (!isResult && arg.entity .has_value ())
6027+ argPosition++;
6028+
60116029 if (arg.passBy == PassBy::AddressAndLength) {
60126030 if (callee.characterize ().IsBindC ())
60136031 return ;
@@ -6018,11 +6036,12 @@ class FirConverter : public Fortran::lower::AbstractConverter {
60186036 mlir::Value casted =
60196037 builder->createVolatileCast (loc, false , arg.firArgument );
60206038 mlir::Value box = charHelp.createEmboxChar (casted, arg.firLength );
6021- mapBlockArgToDummyOrResult (arg.entity ->get (), box, isResult);
6039+ mapBlockArgToDummyOrResult (arg.entity ->get (), box, isResult,
6040+ isResult ? 0 : argPosition);
60226041 } else {
60236042 if (arg.entity .has_value ()) {
60246043 mapBlockArgToDummyOrResult (arg.entity ->get (), arg.firArgument ,
6025- isResult);
6044+ isResult, isResult ? 0 : argPosition );
60266045 } else {
60276046 assert (funit.parentHasTupleHostAssoc () && " expect tuple argument" );
60286047 }
@@ -6880,13 +6899,22 @@ class FirConverter : public Fortran::lower::AbstractConverter {
68806899 }
68816900
68826901 // / Record the given symbol as a dummy argument of this function.
6883- void registerDummySymbol (Fortran::semantics::SymbolRef symRef) {
6902+ // / \param symRef The symbol representing the dummy argument
6903+ // / \param argNo The 1-based position of this argument in the source (0 =
6904+ // / unknown)
6905+ void registerDummySymbol (Fortran::semantics::SymbolRef symRef,
6906+ unsigned argNo = 0 ) {
68846907 auto *sym = &*symRef;
68856908 registeredDummySymbols.insert (sym);
6909+ if (argNo > 0 )
6910+ dummyArgPositions[sym] = argNo;
68866911 }
68876912
68886913 // / Reset all registered dummy symbols.
6889- void resetRegisteredDummySymbols () { registeredDummySymbols.clear (); }
6914+ void resetRegisteredDummySymbols () {
6915+ registeredDummySymbols.clear ();
6916+ dummyArgPositions.clear ();
6917+ }
68906918
68916919 void setCurrentFunctionUnit (Fortran::lower::pft::FunctionLikeUnit *unit) {
68926920 currentFunctionUnit = unit;
@@ -6928,6 +6956,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
69286956 llvm::SmallPtrSet<const Fortran::semantics::Symbol *, 16 >
69296957 registeredDummySymbols;
69306958
6959+ // / Map from dummy symbols to their 1-based argument positions.
6960+ // / Used to generate debug info with correct argument numbers.
6961+ llvm::DenseMap<const Fortran::semantics::Symbol *, unsigned >
6962+ dummyArgPositions;
6963+
69316964 // / A map of unique names for constant expressions.
69326965 // / The names are used for representing the constant expressions
69336966 // / with global constant initialized objects.
0 commit comments