[clang] [CIR] Cast record size to uint64 to prevent overflow (PR #167525)

Hendrik Hübner via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 11 07:52:35 PST 2025


https://github.com/HendrikHuebner created https://github.com/llvm/llvm-project/pull/167525

`llvm::TypeSize` uses 64bit integers, so we should cast the `recordSize` before multiplying by 8 to prevent an overflow.

>From 393202b15d6851e147cbd60344d712f522655a5c Mon Sep 17 00:00:00 2001
From: hhuebner <hendrik.huebner18 at gmail.com>
Date: Tue, 11 Nov 2025 16:50:55 +0100
Subject: [PATCH] Cast record size to uint64 to prevent overflow

---
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 5897352829891..f7907c76c8ccb 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -341,7 +341,7 @@ RecordType::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
   if (isUnion())
     return dataLayout.getTypeSize(getLargestMember(dataLayout));
 
-  unsigned recordSize = computeStructSize(dataLayout);
+  auto recordSize = static_cast<uint64_t>(computeStructSize(dataLayout));
   return llvm::TypeSize::getFixed(recordSize * 8);
 }
 



More information about the cfe-commits mailing list