mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
Use getTypeAllocSize() instead of getTypeSizeInBits()
The function `getTypeSizeInBits()` was wrongly used in many places when reasoning about memory allocation, memory accesses, and memory offsets, The result was often divided by 8 (possibly losing spare bits) or even multiplied by 8, which makes no sense. These uses were error prone, even if they didn't cause problems yet. The `getTypeAllocSize()` is better suited for these uses, because it returns the number of bytes necessary to allocate an object of the given Type.
This commit is contained in:
committed by
Alessandro Di Federico
parent
0dc77e104f
commit
c940b116a7
+3
-4
@@ -139,7 +139,7 @@ bool CorrectCPUStateUsagePass::runOnModule(Module& TheModule) {
|
||||
|
||||
bool Success = false;
|
||||
if (Load != nullptr) {
|
||||
unsigned Size = DL.getTypeSizeInBits(TheUser->getType()) / 8;
|
||||
unsigned Size = DL.getTypeAllocSize(TheUser->getType());
|
||||
assert(Size != 0);
|
||||
|
||||
unsigned CurrentEnvOffset = CurrentOffset - EnvOffset;
|
||||
@@ -151,7 +151,7 @@ bool CorrectCPUStateUsagePass::runOnModule(Module& TheModule) {
|
||||
TheUser->replaceAllUsesWith(Loaded);
|
||||
} else {
|
||||
Value *ToStore = Store->getValueOperand();
|
||||
unsigned Size = DL.getTypeSizeInBits(ToStore->getType()) / 8;
|
||||
unsigned Size = DL.getTypeAllocSize(ToStore->getType());
|
||||
assert(Size != 0);
|
||||
|
||||
unsigned CurrentEnvOffset = CurrentOffset - EnvOffset;
|
||||
@@ -262,7 +262,7 @@ bool CorrectCPUStateUsagePass::runOnModule(Module& TheModule) {
|
||||
}
|
||||
|
||||
Type *PointeeTy = Var->getType()->getPointerElementType();
|
||||
uint64_t Size = DL.getTypeSizeInBits(PointeeTy) / 8;
|
||||
uint64_t Size = DL.getTypeAllocSize(PointeeTy);
|
||||
|
||||
Value *Address = Builder.CreateAdd(Builder.getInt64(Offset),
|
||||
BasePtr);
|
||||
@@ -561,7 +561,6 @@ VariableManager::VariableManager(Module& TheModule,
|
||||
if (startsWith(HelperFunction.getName(), HelperPrefix)
|
||||
&& HelperFunction.getFunctionType()->getNumParams() > 1) {
|
||||
|
||||
|
||||
for (Type *Candidate : HelperType->params()) {
|
||||
Structs.insert(dyn_cast<StructType>(Candidate));
|
||||
if (Candidate->isPointerTy()) {
|
||||
|
||||
Reference in New Issue
Block a user