[clang] clang: Stop using replace_extension when there's no extension (PR #195335)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Fri May 1 13:02:02 PDT 2026


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/195335

>From ad6e4c400b9f719b85f06eaf4177e08c11a1df75 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 1 May 2026 19:46:39 +0100
Subject: [PATCH 1/2] clang: Stop using replace_extension when there's no
 extension

The offload case is building a fresh filepath and there's no file
extension to replace. Just directly append the file extension to avoid
clobbering part of the path name if the triple contains a period.

Avoids confusing test updates in future triple patch.
---
 clang/lib/Driver/Driver.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c98ac919f7d2a..e120fdd743826 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6037,10 +6037,11 @@ static void handleTimeTrace(Compilation &C, const ArgList &Args,
       if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
         Path = llvm::sys::path::parent_path(FinalOutput->getValue());
       llvm::sys::path::append(Path, TraceName);
+      Path += ".json";
     } else {
       Path = Result.getFilename();
+      llvm::sys::path::replace_extension(Path, "json");
     }
-    llvm::sys::path::replace_extension(Path, "json");
   }
   const char *ResultFile = C.getArgs().MakeArgString(Path);
   C.addTimeTraceFile(ResultFile, JA);

>From 37c9464487f03ace35fe2cfb481ebdb2ad0229fd Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 1 May 2026 20:58:00 +0100
Subject: [PATCH 2/2] Fix other path

---
 clang/lib/Driver/Driver.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e120fdd743826..0204e87618111 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6029,6 +6029,7 @@ static void handleTimeTrace(Compilation &C, const ArgList &Args,
       Path = DumpDir->getValue();
       Path += llvm::sys::path::stem(BaseInput);
       Path += OffloadingPrefix;
+      Path += ".json";
     } else if (!OffloadingPrefix.empty()) {
       // For offloading, derive path from -o output directory combined with
       // the input filename and offload prefix.



More information about the cfe-commits mailing list