[clang] e87e55e - Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t
Daniel Grumberg via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 11 01:25:07 PDT 2020
Author: Daniel Grumberg
Date: 2020-06-11T09:12:29+01:00
New Revision: e87e55edbc798c1c73963151f114df775b1ec460
URL: https://github.com/llvm/llvm-project/commit/e87e55edbc798c1c73963151f114df775b1ec460
DIFF: https://github.com/llvm/llvm-project/commit/e87e55edbc798c1c73963151f114df775b1ec460.diff
LOG: Make ASTFileSignature an array of 20 uint8_t instead of 5 uint32_t
Reviewers: aprantl, dexonsmith, Bigcheese
Subscribers: arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D81347
Added:
Modified:
clang/include/clang/Basic/Module.h
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/GlobalModuleIndex.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index b14f6b59dd8c..6b932a9a84d0 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -20,9 +20,9 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
@@ -30,6 +30,7 @@
#include <cassert>
#include <cstdint>
#include <ctime>
+#include <iterator>
#include <string>
#include <utility>
#include <vector>
@@ -52,12 +53,33 @@ class TargetInfo;
using ModuleId = SmallVector<std::pair<std::string, SourceLocation>, 2>;
/// The signature of a module, which is a hash of the AST content.
-struct ASTFileSignature : std::array<uint32_t, 5> {
- ASTFileSignature(std::array<uint32_t, 5> S = {{0}})
- : std::array<uint32_t, 5>(std::move(S)) {}
+struct ASTFileSignature : std::array<uint8_t, 20> {
+ using BaseT = std::array<uint8_t, 20>;
+
+ static constexpr size_t size = std::tuple_size<BaseT>::value;
+
+ ASTFileSignature(BaseT S = {{0}}) : BaseT(std::move(S)) {}
+
+ explicit operator bool() const { return *this != BaseT({{0}}); }
+
+ static ASTFileSignature create(StringRef Bytes) {
+ return create(Bytes.bytes_begin(), Bytes.bytes_end());
+ }
+
+ static ASTFileSignature createDISentinel() {
+ ASTFileSignature Sentinel;
+ Sentinel.fill(0xFF);
+ return Sentinel;
+ }
+
+ template <typename InputIt>
+ static ASTFileSignature create(InputIt First, InputIt Last) {
+ assert(std::distance(First, Last) == size &&
+ "Wrong amount of bytes to create an ASTFileSignature");
- explicit operator bool() const {
- return *this != std::array<uint32_t, 5>({{0}});
+ ASTFileSignature Signature;
+ std::copy(First, Last, Signature.begin());
+ return Signature;
}
};
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 65d513c8cf05..6965c4a1209c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2535,10 +2535,14 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
// PCH files don't have a signature field in the control block,
// but LLVM detects skeleton CUs by looking for a non-zero DWO id.
// We use the lower 64 bits for debug info.
- uint64_t Signature =
- Mod.getSignature()
- ? (uint64_t)Mod.getSignature()[1] << 32 | Mod.getSignature()[0]
- : ~1ULL;
+
+ uint64_t Signature = 0;
+ if (const auto &ModSig = Mod.getSignature()) {
+ for (unsigned I = 0; I != sizeof(Signature); ++I)
+ Signature |= (uint64_t)ModSig[I] << (I * 8);
+ } else {
+ Signature = ~1ULL;
+ }
llvm::DIBuilder DIB(CGM.getModule());
SmallString<0> PCM;
if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 284e8022a3c4..0c7e5f4598f8 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -173,8 +173,8 @@ class PCHContainerGenerator : public ASTConsumer {
// Prepare CGDebugInfo to emit debug info for a clang module.
auto *DI = Builder->getModuleDebugInfo();
StringRef ModuleName = llvm::sys::path::filename(MainFileName);
- DI->setPCHDescriptor({ModuleName, "", OutputFileName,
- ASTFileSignature{{{~0U, ~0U, ~0U, ~0U, ~1U}}}});
+ DI->setPCHDescriptor(
+ {ModuleName, "", OutputFileName, ASTFileSignature::createDISentinel()});
DI->setModuleMap(MMap);
}
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 87987064b747..673b65d543fc 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2791,10 +2791,10 @@ ASTReader::ReadControlBlock(ModuleFile &F,
ReadUntranslatedSourceLocation(Record[Idx++]);
off_t StoredSize = (off_t)Record[Idx++];
time_t StoredModTime = (time_t)Record[Idx++];
- ASTFileSignature StoredSignature = {
- {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
- (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
- (uint32_t)Record[Idx++]}}};
+ auto FirstSignatureByte = Record.begin() + Idx;
+ ASTFileSignature StoredSignature = ASTFileSignature::create(
+ FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+ Idx += ASTFileSignature::size;
std::string ImportedName = ReadString(Record, Idx);
std::string ImportedFile;
@@ -4734,7 +4734,7 @@ ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl(
switch ((UnhashedControlBlockRecordTypes)MaybeRecordType.get()) {
case SIGNATURE:
if (F)
- std::copy(Record.begin(), Record.end(), F->Signature.data());
+ F->Signature = ASTFileSignature::create(Record.begin(), Record.end());
break;
case DIAGNOSTIC_OPTIONS: {
bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0;
@@ -5023,8 +5023,8 @@ static ASTFileSignature readASTFileSignature(StringRef PCH) {
return ASTFileSignature();
}
if (SIGNATURE == MaybeRecord.get())
- return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
- (uint32_t)Record[3], (uint32_t)Record[4]}}};
+ return ASTFileSignature::create(Record.begin(),
+ Record.begin() + ASTFileSignature::size);
}
}
@@ -5322,7 +5322,9 @@ bool ASTReader::readASTFileControlBlock(
unsigned Idx = 0, N = Record.size();
while (Idx < N) {
// Read information about the AST file.
- Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature
+ Idx +=
+ 1 + 1 + 1 + 1 +
+ ASTFileSignature::size; // Kind, ImportLoc, Size, ModTime, Signature
std::string ModuleName = ReadString(Record, Idx);
std::string Filename = ReadString(Record, Idx);
ResolveImportedPath(Filename, ModuleDir);
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index e1fbe566f796..51208726be36 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1032,16 +1032,7 @@ ASTFileSignature ASTWriter::createSignature(StringRef Bytes) {
Hasher.update(ArrayRef<uint8_t>(Bytes.bytes_begin(), Bytes.size()));
auto Hash = Hasher.result();
- // Convert to an array [5*i32].
- ASTFileSignature Signature;
- auto LShift = [&](unsigned char Val, unsigned Shift) {
- return (uint32_t)Val << Shift;
- };
- for (int I = 0; I != 5; ++I)
- Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) |
- LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0);
-
- return Signature;
+ return ASTFileSignature::create(Hash);
}
ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp
index 462d29c2a0f1..958cca734572 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -643,10 +643,10 @@ llvm::Error GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
// Skip the stored signature.
// FIXME: we could read the signature out of the import and validate it.
- ASTFileSignature StoredSignature = {
- {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
- (uint32_t)Record[Idx++], (uint32_t)Record[Idx++],
- (uint32_t)Record[Idx++]}}};
+ auto FirstSignatureByte = Record.begin() + Idx;
+ ASTFileSignature StoredSignature = ASTFileSignature::create(
+ FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size);
+ Idx += ASTFileSignature::size;
// Skip the module name (currently this is only used for prebuilt
// modules while here we are only dealing with cached).
@@ -704,9 +704,8 @@ llvm::Error GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
// Get Signature.
if (State == DiagnosticOptionsBlock && Code == SIGNATURE)
- getModuleFileInfo(File).Signature = {
- {{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2],
- (uint32_t)Record[3], (uint32_t)Record[4]}}};
+ getModuleFileInfo(File).Signature = ASTFileSignature::create(
+ Record.begin(), Record.begin() + ASTFileSignature::size);
// We don't care about this record.
}
More information about the cfe-commits
mailing list