[flang-commits] [flang] [flang][debuginfo] Use <stdin> for file name when reading from stdin (PR #176263)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Thu Jan 15 14:53:31 PST 2026
https://github.com/tarunprabhu created https://github.com/llvm/llvm-project/pull/176263
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
>From f54d6a3e79091cc42b0c4dc67ab312ae44321b18 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun at lanl.gov>
Date: Thu, 15 Jan 2026 15:48:30 -0700
Subject: [PATCH] [flang][debuginfo] Use <stdin> for file name when reading
from stdin
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
---
flang/lib/Parser/source.cpp | 2 +-
.../input-from-stdin/debug-info-filename.f90 | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Driver/input-from-stdin/debug-info-filename.f90
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
More information about the flang-commits
mailing list