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:
Pietro Fezzardi
2018-02-16 10:31:48 +01:00
committed by Alessandro Di Federico
parent 0dc77e104f
commit c940b116a7
3 changed files with 6 additions and 7 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ bool GeneratedCodeBasicInfo::runOnFunction(llvm::Function &F) {
SP = M->getGlobalVariable(QMD.extract<StringRef>(Tuple, 3), true);
Type *PCType = PC->getType()->getPointerElementType();
PCRegSize = M->getDataLayout().getTypeSizeInBits(PCType) / 8;
PCRegSize = M->getDataLayout().getTypeAllocSize(PCType);
for (BasicBlock &BB : F) {
if (!BB.empty()) {