[clang] 641ff6d - [DebugInfo] Add option for producing no source-file hash (#148657)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 14 12:48:44 PDT 2025
Author: Jeremy Morse
Date: 2025-07-14T20:48:41+01:00
New Revision: 641ff6db383d0730ae2587c86aa59b6b3cf8341d
URL: https://github.com/llvm/llvm-project/commit/641ff6db383d0730ae2587c86aa59b6b3cf8341d
DIFF: https://github.com/llvm/llvm-project/commit/641ff6db383d0730ae2587c86aa59b6b3cf8341d.diff
LOG: [DebugInfo] Add option for producing no source-file hash (#148657)
Clang can chose which sort of source-file hash is attached to a DIFile
metadata node. However, whenever hashing is possible, we /always/ attach
a hash. This patch permits users who want DWARF5 but don't want the file
hashes to opt out, by adding a "none" option to the -gsrc-hash option
that skips hash computation.
Added:
Modified:
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-file-checksum.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index fe634d221b424..f6c61f202890e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -115,6 +115,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
DSH_MD5,
DSH_SHA1,
DSH_SHA256,
+ DSH_NONE,
};
// This field stores one of the allowed values for the option
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 2e070d6d64508..d0b54a446309b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4690,8 +4690,8 @@ def gsimple_template_names_EQ
Values<"simple,mangled">, Visibility<[CC1Option]>;
def gsrc_hash_EQ : Joined<["-"], "gsrc-hash=">,
Group<g_flags_Group>, Visibility<[CC1Option]>,
- Values<"md5,sha1,sha256">,
- NormalizedValues<["DSH_MD5", "DSH_SHA1", "DSH_SHA256"]>,
+ Values<"md5,sha1,sha256,none">,
+ NormalizedValues<["DSH_MD5", "DSH_SHA1", "DSH_SHA256", "DSH_NONE"]>,
NormalizedValuesScope<"CodeGenOptions">,
MarshallingInfoEnum<CodeGenOpts<"DebugSrcHash">, "DSH_MD5">;
def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">,
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 5240853199c11..f97c7b6445984 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -514,6 +514,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum) const {
case clang::CodeGenOptions::DSH_SHA256:
llvm::toHex(llvm::SHA256::hash(Data), /*LowerCase=*/true, Checksum);
return llvm::DIFile::CSK_SHA256;
+ case clang::CodeGenOptions::DSH_NONE:
+ return std::nullopt;
}
llvm_unreachable("Unhandled DebugSrcHashKind enum");
}
diff --git a/clang/test/CodeGen/debug-info-file-checksum.c b/clang/test/CodeGen/debug-info-file-checksum.c
index 2ca91d605d1c4..30138e74a3ebb 100644
--- a/clang/test/CodeGen/debug-info-file-checksum.c
+++ b/clang/test/CodeGen/debug-info-file-checksum.c
@@ -13,12 +13,15 @@
// RUN: | FileCheck --check-prefix=SHA256 %s
// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
// RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -Xclang -gsrc-hash=md5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -Xclang -gsrc-hash=none -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s --check-prefix=NONE
// Check that "checksum" is created correctly for the compiled file.
// CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
// SHA1: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA1, checksum: "6f6eeaba705ad6db6fbb05c2cbcf3cbb3e374bcd")
// SHA256: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA256, checksum: "2d49b53859e57898a0f8c16ff1fa4d99306b8ec28d65cf7577109761f0d56197")
+// NONE: !DIFile(filename:{{.*}}, directory:{{.*}})
// Ensure #line directives (in already pre-processed files) do not emit checksums
// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-pre.cpp -o - | FileCheck %s --check-prefix NOCHECKSUM
More information about the cfe-commits
mailing list