[CIR] Cast record size to uint64 to prevent overflow#167525
Merged
andykaylor merged 1 commit intollvm:mainfrom Nov 12, 2025
Merged
[CIR] Cast record size to uint64 to prevent overflow#167525andykaylor merged 1 commit intollvm:mainfrom
andykaylor merged 1 commit intollvm:mainfrom
Conversation
Member
|
@llvm/pr-subscribers-clangir @llvm/pr-subscribers-clang Author: Hendrik Hübner (HendrikHuebner) Changes
Full diff: https://github.com/llvm/llvm-project/pull/167525.diff 1 Files Affected:
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);
}
|
andykaylor
approved these changes
Nov 12, 2025
Contributor
andykaylor
left a comment
There was a problem hiding this comment.
Have you seen a case where this overflow happens? Your change seems good. Normally we require tests for every change, but in this case I don't think that's necessary.
Contributor
Author
|
I have not tried reproducing it, I just noticed this while reading the code. Itt seems safer to add the cast. |
git-crd
pushed a commit
to git-crd/crd-llvm-project
that referenced
this pull request
Nov 13, 2025
`llvm::TypeSize` uses 64bit integers, so we should cast the `recordSize` before multiplying by 8 to prevent an overflow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
llvm::TypeSizeuses 64bit integers, so we should cast therecordSizebefore multiplying by 8 to prevent an overflow.