[flang-commits] [flang] [flang] Represent use statement in fir. (PR #168106)
Abid Qadeer via flang-commits
flang-commits at lists.llvm.org
Fri Dec 19 09:51:19 PST 2025
================
@@ -222,6 +222,75 @@ static mlir::FlatSymbolRefAttr gatherComponentInit(
return mlir::FlatSymbolRefAttr::get(mlirContext, name);
}
+/// Emit fir.use_stmt operations for USE statements in the given scope
+static void
+emitUseStatementsFromScope(Fortran::lower::AbstractConverter &converter,
+ mlir::OpBuilder &builder, mlir::Location loc,
+ const Fortran::semantics::Scope &scope) {
+ mlir::MLIRContext *context = builder.getContext();
+
+ for (const auto &preservedStmt : scope.preservedUseStmts()) {
+
+ auto getMangledName = [&](const std::string &localName) -> std::string {
+ Fortran::parser::CharBlock charBlock{localName.data(), localName.size()};
+ const auto *sym = scope.FindSymbol(charBlock);
+ if (!sym)
+ return "";
----------------
abidh wrote:
Thanks for taking a look again. The `fir.use_stmt` is generated for the debug information purpose only. It should not have any impact on program correctness or functionality. So it would be wrong to generate an error or warning which would not be there otherwise.
There are 3 total cases of returning "". The first one (!sym) is just defensive programming. I could not trigger the condition. The other 2 are cases for which we neither have a good debug representation nor converter.mangleName handles them. So it is safe to ignore.
https://github.com/llvm/llvm-project/pull/168106
More information about the flang-commits
mailing list