Skip to content

Commit 7271c2f

Browse files
authored
[Comgr] Fix implicit cast from integer to single element ArrayRef<uint8_t> (llvm#1661)
2 parents f0f8c71 + 7098991 commit 7271c2f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

amd/comgr/src/comgr-cache-command.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,19 @@ std::optional<size_t> CachedCommandAdaptor::searchComgrTmpModel(StringRef S) {
6767
return Pos;
6868
}
6969

70+
void CachedCommandAdaptor::addUInt(CachedCommandAdaptor::HashAlgorithm &H,
71+
uint64_t I) {
72+
uint8_t Bytes[sizeof(I)];
73+
memcpy(&Bytes, &I, sizeof(I));
74+
H.update(Bytes);
75+
}
76+
7077
void CachedCommandAdaptor::addString(CachedCommandAdaptor::HashAlgorithm &H,
7178
StringRef S) {
7279
// hash size + contents to avoid collisions
7380
// for example, we have to ensure that the result of hashing "AA" "BB" is
7481
// different from "A" "ABB"
75-
H.update(S.size());
82+
addUInt(H, S.size());
7683
H.update(S);
7784
}
7885

amd/comgr/src/comgr-cache-command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CachedCommandAdaptor {
3939

4040
// helper to work around the comgr-xxxxx string appearing in files
4141
static void addFileContents(HashAlgorithm &H, llvm::StringRef Buf);
42+
static void addUInt(HashAlgorithm &H, uint64_t I);
4243
static void addString(HashAlgorithm &H, llvm::StringRef S);
4344
static std::optional<size_t> searchComgrTmpModel(llvm::StringRef S);
4445

amd/comgr/src/comgr-unbundle-command.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ CachedCommandAdaptor::ActionClass UnbundleCommand::getClass() const {
122122
}
123123

124124
void UnbundleCommand::addOptionsIdentifier(HashAlgorithm &H) const {
125-
H.update(Config.TargetNames.size());
125+
addUInt(H, Config.TargetNames.size());
126126
for (StringRef Target : Config.TargetNames) {
127127
CachedCommandAdaptor::addString(H, Target);
128128
}
@@ -150,8 +150,8 @@ Error UnbundleCommand::addInputIdentifier(HashAlgorithm &H) const {
150150
// contents should give the same result, regardless of the compression
151151
// algorithm or header version. Since the hash used by the offload bundler is
152152
// not a cryptographic hash, we also add the uncompressed file size.
153-
H.update(MaybeHeader->Hash);
154-
H.update(MaybeHeader->UncompressedFileSize);
153+
addUInt(H, MaybeHeader->Hash);
154+
addUInt(H, MaybeHeader->UncompressedFileSize);
155155
return Error::success();
156156
}
157157

0 commit comments

Comments
 (0)