[llvm] [BOLT] Avoid UB due to misaligned access. (PR #174990)
Harald van Dijk via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 8 07:17:35 PST 2026
https://github.com/hvdijk created https://github.com/llvm/llvm-project/pull/174990
There is no guarantee that PatchOffset is suitably aligned for uint32_t, and in BOLT's own tests, it is not aligned for uint32_t.
Fixes test failures seen with LLVM_USE_SANITIZER=Undefined.
>From 66ebe870cf9ef6a4c8b11671cd26c20940786bd1 Mon Sep 17 00:00:00 2001
From: Harald van Dijk <hdijk at accesssoftek.com>
Date: Thu, 8 Jan 2026 15:16:35 +0000
Subject: [PATCH] [BOLT] Avoid UB due to misaligned access.
There is no guarantee that PatchOffset is suitably aligned for uint32_t,
and in BOLT's own tests, it is not aligned for uint32_t.
Fixes test failures seen with LLVM_USE_SANITIZER=Undefined.
---
bolt/lib/Core/DebugNames.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Core/DebugNames.cpp b/bolt/lib/Core/DebugNames.cpp
index 5272d402be7f3..787ef742d5eec 100644
--- a/bolt/lib/Core/DebugNames.cpp
+++ b/bolt/lib/Core/DebugNames.cpp
@@ -648,9 +648,9 @@ void DWARF5AcceleratorTable::writeEntries() {
if (const auto Iter = EntryRelativeOffsets.find(*ParentOffset);
Iter != EntryRelativeOffsets.end()) {
const uint64_t PatchOffset = Entry->getPatchOffset();
- uint32_t *Ptr =
- reinterpret_cast<uint32_t *>(&EntriesBuffer->data()[PatchOffset]);
- *Ptr = Iter->second;
+ uint32_t RelativeOffset = Iter->second;
+ memcpy(&EntriesBuffer->data()[PatchOffset], &RelativeOffset,
+ sizeof(uint32_t));
} else {
BC.errs() << "BOLT-WARNING: [internal-dwarf-warning]: Could not find "
"entry with offset "
More information about the llvm-commits
mailing list