[clang] [dyndbg][Clang] Avoid null pointer dereference from #216307 (PR #216625)

Thurston Dang via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 16 19:45:07 PDT 2026


https://github.com/thurstond created https://github.com/llvm/llvm-project/pull/216625

As reported in https://github.com/llvm/llvm-project/pull/216307#issuecomment-5311023374, the new tests fail on UBSan buildbots (e.g., https://lab.llvm.org/buildbot/#/builders/25/builds/19323) because the directory may be empty (only the file is initialized), and the StringRef from getDirectory() is default-initialized.

This patch attempts to fix-forward by not hashing the output of getDirectory() if it is empty.

>From fa97b03b1346cea4c0fcf404964241b81e8fc05a Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Mon, 17 Aug 2026 02:43:25 +0000
Subject: [PATCH] [dyndbg][Clang] Avoid null pointer dereference from #216307

As reported in https://github.com/llvm/llvm-project/pull/216307#issuecomment-5311023374,
the new tests fail on UBSan buildbots (e.g., https://lab.llvm.org/buildbot/#/builders/25/builds/19323) because the directory may be empty (only the file is initialized), and the StringRef from getDirectory() is default-initialized.

This patch attempts to fix-forward by not hashing the output of getDirectory() if it is empty.
---
 clang/lib/CodeGen/BackendUtil.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 75c3d16e455f1..e55d242cde68a 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1527,7 +1527,9 @@ static void createAndEmbedModuleForDynamicDebugging(
     // the same source file compiled twice won't generate unique hashes.
     Hash.update(CGOpts.CmdArgs);
     for (auto *CU : M->debug_compile_units()) {
-      Hash.update(CU->getDirectory());
+      if (CU->getDirectory().size() > 0)
+        Hash.update(CU->getDirectory());
+
       Hash.update(CU->getFilename());
     }
 



More information about the cfe-commits mailing list