[clang] 77bdc16 - [dyndbg][Clang] Avoid memcpy on nullptr from #216307 (#216625)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 16 20:56:33 PDT 2026
Author: Thurston Dang
Date: 2026-08-16T20:56:28-07:00
New Revision: 77bdc160b4ae80a4a887e927afb2934a6b417d41
URL: https://github.com/llvm/llvm-project/commit/77bdc160b4ae80a4a887e927afb2934a6b417d41
DIFF: https://github.com/llvm/llvm-project/commit/77bdc160b4ae80a4a887e927afb2934a6b417d41.diff
LOG: [dyndbg][Clang] Avoid memcpy on nullptr from #216307 (#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 [*]). The StringRef
from getDirectory() would be default-initialized, and hashing it results
in memcpy'ing from a null pointer.
This patch attempts to fix-forward by not hashing the output of
getDirectory() if it is empty.
[*] e.g., `!3 = !DIFile(filename:
"/usr/local/google/home/thurston/llvm-projectA/clang/test/DebugInfo/DynamicDebugging/<stdin>",
directory: "")`
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
Removed:
################################################################################
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