Skip to content

Commit 641ff6d

Browse files
authored
[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.
1 parent db15c23 commit 641ff6d

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
115115
DSH_MD5,
116116
DSH_SHA1,
117117
DSH_SHA256,
118+
DSH_NONE,
118119
};
119120

120121
// This field stores one of the allowed values for the option

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,8 +4690,8 @@ def gsimple_template_names_EQ
46904690
Values<"simple,mangled">, Visibility<[CC1Option]>;
46914691
def gsrc_hash_EQ : Joined<["-"], "gsrc-hash=">,
46924692
Group<g_flags_Group>, Visibility<[CC1Option]>,
4693-
Values<"md5,sha1,sha256">,
4694-
NormalizedValues<["DSH_MD5", "DSH_SHA1", "DSH_SHA256"]>,
4693+
Values<"md5,sha1,sha256,none">,
4694+
NormalizedValues<["DSH_MD5", "DSH_SHA1", "DSH_SHA256", "DSH_NONE"]>,
46954695
NormalizedValuesScope<"CodeGenOptions">,
46964696
MarshallingInfoEnum<CodeGenOpts<"DebugSrcHash">, "DSH_MD5">;
46974697
def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">,

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum) const {
514514
case clang::CodeGenOptions::DSH_SHA256:
515515
llvm::toHex(llvm::SHA256::hash(Data), /*LowerCase=*/true, Checksum);
516516
return llvm::DIFile::CSK_SHA256;
517+
case clang::CodeGenOptions::DSH_NONE:
518+
return std::nullopt;
517519
}
518520
llvm_unreachable("Unhandled DebugSrcHashKind enum");
519521
}

clang/test/CodeGen/debug-info-file-checksum.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
// RUN: | FileCheck --check-prefix=SHA256 %s
1414
// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
1515
// RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
16+
// RUN: %clang -emit-llvm -S -gdwarf-5 -Xclang -gsrc-hash=md5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
17+
// 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
1618

1719
// Check that "checksum" is created correctly for the compiled file.
1820

1921
// CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
2022
// SHA1: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA1, checksum: "6f6eeaba705ad6db6fbb05c2cbcf3cbb3e374bcd")
2123
// SHA256: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA256, checksum: "2d49b53859e57898a0f8c16ff1fa4d99306b8ec28d65cf7577109761f0d56197")
24+
// NONE: !DIFile(filename:{{.*}}, directory:{{.*}})
2225

2326
// Ensure #line directives (in already pre-processed files) do not emit checksums
2427
// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-pre.cpp -o - | FileCheck %s --check-prefix NOCHECKSUM

0 commit comments

Comments
 (0)