summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Korous <jkorous@apple.com>2018-03-19 20:26:18 +0000
committerJan Korous <jkorous@apple.com>2018-03-19 20:26:18 +0000
commitbd5ff79dd0b007489d4776ea0cb4c8cb4bed3fcd (patch)
tree7ec5f6aa774480e9d50409e0da85ebad76d93c04
parentee1f4586f6e8cdf29f29677c2ac89dfd9f006be0 (diff)
downloadbcm5719-llvm-bd5ff79dd0b007489d4776ea0cb4c8cb4bed3fcd.tar.gz
bcm5719-llvm-bd5ff79dd0b007489d4776ea0cb4c8cb4bed3fcd.zip
[clangd] Fix undefined behavior due to misaligned type cast
The current code was casting pointer to a misaligned type which is undefined behavior. Found by compiling with Undefined Behavior Sanitizer and running tests (check-clang-tools). llvm-svn: 327902
-rw-r--r--clang-tools-extra/clangd/index/Index.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/index/Index.h b/clang-tools-extra/clangd/index/Index.h
index 7da3a50ea47..1b752b672fc 100644
--- a/clang-tools-extra/clangd/index/Index.h
+++ b/clang-tools-extra/clangd/index/Index.h
@@ -61,7 +61,9 @@ private:
friend llvm::hash_code hash_value(const SymbolID &ID) {
// We already have a good hash, just return the first bytes.
static_assert(sizeof(size_t) <= HashByteLength, "size_t longer than SHA1!");
- return *reinterpret_cast<const size_t *>(ID.HashValue.data());
+ size_t Result;
+ memcpy(&Result, ID.HashValue.data(), sizeof(size_t));
+ return llvm::hash_code(Result);
}
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const SymbolID &ID);
OpenPOWER on IntegriCloud