Skip to content

Commit f2e50cf

Browse files
earnolVladislav Aranov
authored andcommitted
Automerge: [ubsan] Use internal_memcpy to copy ubsan bits size (#121586)
While fetching amounts of bits used to correctly display ubsan value reinterpret_cast was used, however as noted by Jakub Jelínek in llvm/llvm-project#96240 discussion it might cause issues due to potentially unaligned memory access. The patch addresses this problem. Co-authored-by: Vladislav Aranov <[email protected]>
2 parents a02a83f + b7a6e9d commit f2e50cf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler-rt/lib/ubsan/ubsan_value.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,12 @@ class TypeDescriptor {
150150

151151
unsigned getIntegerBitCount() const {
152152
DCHECK(isIntegerTy());
153-
if (isSignedBitIntTy())
154-
return *reinterpret_cast<const u32 *>(getBitIntBitCountPointer());
155-
else
153+
if (isSignedBitIntTy()) {
154+
u32 BitCountValue;
155+
internal_memcpy(&BitCountValue, getBitIntBitCountPointer(),
156+
sizeof(BitCountValue));
157+
return BitCountValue;
158+
} else
156159
return getIntegerBitWidth();
157160
}
158161

0 commit comments

Comments
 (0)