[llvm] ef0f6d0 - [Support] Add assert for DataBytes in calculateReflectedCRC32 (#228688)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 05:12:20 PDT 2026


Author: Shreesh Adiga
Date: 2026-10-03T12:12:11Z
New Revision: ef0f6d06eb188730224e9de54576aa69d4ee2d5f

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

LOG: [Support] Add assert for DataBytes in calculateReflectedCRC32 (#228688)

Add an assertion to calculateReflectedCRC32 to check DataBytes is one of
the expected value (1, 2, 4, or 8 bytes).

Co-authored-by: Jared Wyles <jared.wyles at gmail.com>

Added: 
    

Modified: 
    llvm/include/llvm/Support/CRC.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/CRC.h b/llvm/include/llvm/Support/CRC.h
index 39c03e2e69c03..d511115b216f5 100644
--- a/llvm/include/llvm/Support/CRC.h
+++ b/llvm/include/llvm/Support/CRC.h
@@ -15,6 +15,7 @@
 
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataTypes.h"
+#include <cassert>
 
 namespace llvm {
 template <typename T> class ArrayRef;
@@ -33,6 +34,9 @@ LLVM_ABI uint32_t crc32(uint32_t CRC, ArrayRef<uint8_t> Data);
 constexpr inline uint32_t calculateReflectedCRC32(uint32_t Crc, uint64_t Data,
                                                   unsigned DataBytes,
                                                   uint32_t Poly) {
+  assert(
+      (DataBytes == 1 || DataBytes == 2 || DataBytes == 4 || DataBytes == 8) &&
+      "Data Bytes out of range.");
   uint32_t Result = Crc;
   // Process each byte
   for (unsigned I = 0; I != DataBytes; ++I) {


        


More information about the llvm-commits mailing list