[flang-commits] [flang] [flang] Remove hardcoded bits from AddDebugInfo. (PR #89231)
via flang-commits
flang-commits at lists.llvm.org
Fri Apr 19 01:48:23 PDT 2024
================
@@ -52,21 +55,40 @@ void AddDebugInfoPass::runOnOperation() {
mlir::ModuleOp module = getOperation();
mlir::MLIRContext *context = &getContext();
mlir::OpBuilder builder(context);
- std::string inputFilePath("-");
- if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>())
- inputFilePath = fileLoc.getFilename().getValue();
+ llvm::StringRef fileName;
+ std::string filePath;
+ // We need 2 type of file paths here.
+ // 1. Name of the file as was presented to compiler. This can be absolute
+ // or relative to 2.
+ // 2. Current working directory
+ //
+ // We are also dealing with 2 different situations below. One is normal
+ // compilation where we will have a value in 'inputFilename' and we can
+ // obtain the current directory using 'current_path'.
+ // The 2nd case is when this pass is invoked directly from 'fir-opt' tool.
+ // In that case, 'inputFilename' may be empty. Location embedded in the
+ // module will be used to get file name and its directory.
+ if (inputFilename.empty()) {
+ if (auto fileLoc = module.getLoc().dyn_cast<mlir::FileLineColLoc>()) {
+ fileName = llvm::sys::path::filename(fileLoc.getFilename().getValue());
+ filePath = llvm::sys::path::parent_path(fileLoc.getFilename().getValue());
+ } else
+ fileName = "-";
+ } else {
+ fileName = inputFilename;
+ llvm::SmallString<256> cwd;
+ if (!llvm::sys::fs::current_path(cwd))
----------------
jeanPerier wrote:
Isn't `current_path` the working directory where the compiler is being run? If so, that could be different from the file directory.
https://github.com/llvm/llvm-project/pull/89231
More information about the flang-commits
mailing list