[llvm-branch-commits] [clang] release/22.x: [clang][CodeView] Prevent the input name from appearing in LF_BUILDINFO (#194140) (PR #194348)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 27 04:33:49 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: llvmbot
<details>
<summary>Changes</summary>
Backport 27ebc84
Requested by: @<!-- -->aganea
---
Full diff: https://github.com/llvm/llvm-project/pull/194348.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+19-3)
- (modified) clang/test/DebugInfo/Generic/codeview-buildinfo.c (+33)
``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index d411ef1bf8763..5f147c3754246 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -322,7 +322,8 @@ static bool actionRequiresCodeGen(BackendAction Action) {
}
static std::string flattenClangCommandLine(ArrayRef<std::string> Args,
- StringRef MainFilename) {
+ StringRef MainFilename,
+ ArrayRef<StringRef> InputFiles) {
if (Args.empty())
return std::string{};
@@ -341,7 +342,15 @@ static std::string flattenClangCommandLine(ArrayRef<std::string> Args,
i++; // Skip this argument and next one.
continue;
}
- if (Arg.starts_with("-object-file-name") || Arg == MainFilename)
+ if (Arg.starts_with("-object-file-name"))
+ continue;
+ // Strip the source positional, matching either MainFilename (the
+ // -main-file-name basename) or one of the resolved frontend input paths
+ // (which is what the cc1 positional looks like for an absolute driver
+ // input). Avoid a generic basename match: it would also strip values of
+ // args like `-include <path>` whose trailing component happens to equal
+ // the source basename.
+ if (Arg == MainFilename || llvm::is_contained(InputFiles, Arg))
continue;
// Skip fmessage-length for reproducibility.
if (Arg.starts_with("-fmessage-length"))
@@ -519,8 +528,15 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.MCOptions.IASSearchPaths.push_back(
Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path);
Options.MCOptions.Argv0 = CodeGenOpts.Argv0 ? CodeGenOpts.Argv0 : "";
+ // Pass the resolved frontend inputs so flattenClangCommandLine can strip
+ // the cc1 source positional even when the driver received an absolute path
+ // (which won't match CodeGenOpts.MainFileName, that's just the basename).
+ SmallVector<StringRef, 1> InputFiles;
+ for (const auto &Input : CI.getFrontendOpts().Inputs)
+ if (Input.isFile())
+ InputFiles.push_back(Input.getFile());
Options.MCOptions.CommandlineArgs = flattenClangCommandLine(
- CodeGenOpts.CommandLineArgs, CodeGenOpts.MainFileName);
+ CodeGenOpts.CommandLineArgs, CodeGenOpts.MainFileName, InputFiles);
Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile;
Options.MCOptions.PPCUseFullRegisterNames =
CodeGenOpts.PPCUseFullRegisterNames;
diff --git a/clang/test/DebugInfo/Generic/codeview-buildinfo.c b/clang/test/DebugInfo/Generic/codeview-buildinfo.c
index ee6f772944d84..b930e3cc642c4 100644
--- a/clang/test/DebugInfo/Generic/codeview-buildinfo.c
+++ b/clang/test/DebugInfo/Generic/codeview-buildinfo.c
@@ -12,6 +12,18 @@
// RUN: %clang_cl -gcodeview-command-line --target=i686-windows-msvc -Xclang -fmessage-length=100 /c /Z7 /Fo%t.obj -- %s
// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix MESSAGELEN
+// The source filename must be stripped from the embedded cc1 command line
+// whether it's passed to the driver as an absolute or a relative path.
+// See https://github.com/llvm/llvm-project/issues/193900.
+
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix ABSPATH
+
+// RUN: rm -rf %t.relpath && mkdir %t.relpath
+// RUN: cp %s %t.relpath/hello.cpp
+// RUN: cd %t.relpath && %clang_cl --target=i686-windows-msvc /c /Z7 /Fo:hello.obj -- hello.cpp
+// RUN: llvm-pdbutil dump --types %t.relpath/hello.obj | FileCheck %s --check-prefix RELPATH
+
int main(void) { return 42; }
// CHECK: Types (.debug$T)
@@ -45,3 +57,24 @@ int main(void) { return 42; }
// MESSAGELEN: ============================================================
// MESSAGELEN: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
// MESSAGELEN-NOT: -fmessage-length
+
+// The cmdline is the 5th argument of LF_BUILDINFO. The source filename must
+// not appear inside its value (the SourceFile field, the 3rd argument, is
+// reserved for that).
+// ABSPATH: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// ABSPATH-NEXT: 0x{{.*}}: `{{.*}}`
+// ABSPATH-NEXT: 0x{{.*}}: `{{.*}}`
+// ABSPATH-NEXT: 0x{{.*}}: `{{.+[\\/]codeview-buildinfo\.c}}`
+// ABSPATH-NEXT: 0x{{.*}}: ``
+// ABSPATH-NEXT: 0x{{.*}}: `
+// ABSPATH-NOT: {{[^"]*[\\/]codeview-buildinfo\.c}}
+// ABSPATH-SAME: `
+
+// RELPATH: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// RELPATH-NEXT: 0x{{.*}}: `{{.*}}`
+// RELPATH-NEXT: 0x{{.*}}: `{{.*}}`
+// RELPATH-NEXT: 0x{{.*}}: `{{.*hello\.cpp}}`
+// RELPATH-NEXT: 0x{{.*}}: ``
+// RELPATH-NEXT: 0x{{.*}}: `
+// RELPATH-NOT: {{hello\.cpp}}
+// RELPATH-SAME: `
``````````
</details>
https://github.com/llvm/llvm-project/pull/194348
More information about the llvm-branch-commits
mailing list