[flang-commits] [flang] [flang][debuginfo] Use <stdin> for file name when reading from stdin (PR #176263)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 15 14:54:02 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-driver

Author: Tarun Prabhu (tarunprabhu)

<details>
<summary>Changes</summary>

Currently, the DIFile debuginfo nodes use "standard input" as the file name when compiling with -g and reading input from stdin. This has been changed to "<stdin>" for consistency with clang.

Fixes #<!-- -->60288

---
Full diff: https://github.com/llvm/llvm-project/pull/176263.diff


2 Files Affected:

- (modified) flang/lib/Parser/source.cpp (+1-1) 
- (added) flang/test/Driver/input-from-stdin/debug-info-filename.f90 (+14) 


``````````diff
diff --git a/flang/lib/Parser/source.cpp b/flang/lib/Parser/source.cpp
index ae834dc241652..6313373675e5b 100644
--- a/flang/lib/Parser/source.cpp
+++ b/flang/lib/Parser/source.cpp
@@ -142,7 +142,7 @@ bool SourceFile::Open(std::string path, llvm::raw_ostream &error) {
 
 bool SourceFile::ReadStandardInput(llvm::raw_ostream &error) {
   Close();
-  path_ = "standard input";
+  path_ = "<stdin>";
   auto buf_or = llvm::MemoryBuffer::getSTDIN();
   if (!buf_or) {
     auto err = buf_or.getError();
diff --git a/flang/test/Driver/input-from-stdin/debug-info-filename.f90 b/flang/test/Driver/input-from-stdin/debug-info-filename.f90
new file mode 100644
index 0000000000000..9dd950ce87ea0
--- /dev/null
+++ b/flang/test/Driver/input-from-stdin/debug-info-filename.f90
@@ -0,0 +1,14 @@
+! When compiling with debug info, the "file name" should be "<stdin>" for
+! consistency with clang and gfortran. The exception is the first file that is
+! referenced from the DICompileUnit in which the file name is "-". This is also
+! consistent with clang.
+!
+! RUN: cat %s \
+! RUN:     | %flang -g -x f95 -S -emit-llvm -o - - \
+! RUN:     | FileCheck %s
+!
+! CHECK: !DICompileUnit({{.*}}file: ![[DASH:[0-9]+]]
+! CHECK: ![[DASH]] = !DIFile({{.*}}filename: "-"
+! CHECK: !DIFile({{.*}}filename: "<stdin>"
+
+end program

``````````

</details>


https://github.com/llvm/llvm-project/pull/176263


More information about the flang-commits mailing list