[compiler-rt] [ubsan] Use internal_memcpy to copy ubsan bits size (PR #121586)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 3 09:52:31 PST 2025
https://github.com/earnol updated https://github.com/llvm/llvm-project/pull/121586
>From 97011eb791db96bc8dd1ad3d6186870277499a53 Mon Sep 17 00:00:00 2001
From: Vladislav Aranov <vladislav.aranov at ericsson.com>
Date: Fri, 3 Jan 2025 11:56:10 -0500
Subject: [PATCH] [ubsan] Use internal_memcpy to copy ubsan bits size
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
While fetching amounts of bits used to correctly display ubsan
value reinterpret_cast was used, however as noted by Jakub
JelĂnek in https://github.com/llvm/llvm-project/pull/96240
discussion it might cause issues due to potentially unaligned
memory access. The patch addresses this problem.
---
compiler-rt/lib/ubsan/ubsan_value.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/lib/ubsan/ubsan_value.h b/compiler-rt/lib/ubsan/ubsan_value.h
index 430c9ea0dc8d15..ee523cf5ddda50 100644
--- a/compiler-rt/lib/ubsan/ubsan_value.h
+++ b/compiler-rt/lib/ubsan/ubsan_value.h
@@ -150,9 +150,12 @@ class TypeDescriptor {
unsigned getIntegerBitCount() const {
DCHECK(isIntegerTy());
- if (isSignedBitIntTy())
- return *reinterpret_cast<const u32 *>(getBitIntBitCountPointer());
- else
+ if (isSignedBitIntTy()) {
+ u32 BitCountValue;
+ internal_memcpy(&BitCountValue, getBitIntBitCountPointer(),
+ sizeof(BitCountValue));
+ return BitCountValue;
+ } else
return getIntegerBitWidth();
}
More information about the llvm-commits
mailing list