[compiler-rt] b7a6e9d - [ubsan] Use internal_memcpy to copy ubsan bits size (#121586)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 07:59:56 PST 2025


Author: earnol
Date: 2025-01-07T10:59:53-05:00
New Revision: b7a6e9da124142a1bd28895eea768a158901a03b

URL: https://github.com/llvm/llvm-project/commit/b7a6e9da124142a1bd28895eea768a158901a03b
DIFF: https://github.com/llvm/llvm-project/commit/b7a6e9da124142a1bd28895eea768a158901a03b.diff

LOG: [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
https://github.com/llvm/llvm-project/pull/96240 discussion it might
cause issues due to potentially unaligned memory access. The patch
addresses this problem.

Co-authored-by: Vladislav Aranov <vladislav.aranov at ericsson.com>

Added: 
    

Modified: 
    compiler-rt/lib/ubsan/ubsan_value.h

Removed: 
    


################################################################################
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