1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Explicit 64-bit indexer truncation on 32-bit builds

This commit is contained in:
Brian Fiete 2022-02-07 15:35:00 -05:00
parent 390f27c072
commit 7d0121ea27
2 changed files with 10 additions and 1 deletions

View file

@ -486,6 +486,12 @@ void BfIRCodeGen::FixValues(llvm::StructType* structType, llvm::SmallVector<llvm
} }
} }
void BfIRCodeGen::FixIndexer(llvm::Value*& val)
{
if ((int)val->getType()->getScalarSizeInBits() > mPtrSize * 8)
val = mIRBuilder->CreateIntCast(val, llvm::Type::getInt32Ty(*mLLVMContext), false);
}
BfTypeCode BfIRCodeGen::GetTypeCode(llvm::Type* type, bool isSigned) BfTypeCode BfIRCodeGen::GetTypeCode(llvm::Type* type, bool isSigned)
{ {
if (type->isIntegerTy()) if (type->isIntegerTy())
@ -2340,7 +2346,7 @@ void BfIRCodeGen::HandleNextCmd()
SetResult(curId, mIRBuilder->CreateBitCast(gepResult, val->getType())); SetResult(curId, mIRBuilder->CreateBitCast(gepResult, val->getType()));
break; break;
} }
FixIndexer(idx0);
SetResult(curId, mIRBuilder->CreateInBoundsGEP(val, idx0)); SetResult(curId, mIRBuilder->CreateInBoundsGEP(val, idx0));
} }
break; break;
@ -2349,6 +2355,8 @@ void BfIRCodeGen::HandleNextCmd()
CMD_PARAM(llvm::Value*, val); CMD_PARAM(llvm::Value*, val);
CMD_PARAM(llvm::Value*, idx0); CMD_PARAM(llvm::Value*, idx0);
CMD_PARAM(llvm::Value*, idx1); CMD_PARAM(llvm::Value*, idx1);
FixIndexer(idx0);
FixIndexer(idx1);
llvm::Value* indices[2] = { idx0, idx1 }; llvm::Value* indices[2] = { idx0, idx1 };
SetResult(curId, FixGEP(val, mIRBuilder->CreateInBoundsGEP(val, llvm::makeArrayRef(indices)))); SetResult(curId, FixGEP(val, mIRBuilder->CreateInBoundsGEP(val, llvm::makeArrayRef(indices))));
} }

View file

@ -125,6 +125,7 @@ public:
public: public:
void InitTarget(); void InitTarget();
void FixValues(llvm::StructType* structType, llvm::SmallVector<llvm::Value*, 8>& values); void FixValues(llvm::StructType* structType, llvm::SmallVector<llvm::Value*, 8>& values);
void FixIndexer(llvm::Value*& val);
BfTypeCode GetTypeCode(llvm::Type* type, bool isSigned); BfTypeCode GetTypeCode(llvm::Type* type, bool isSigned);
llvm::Type* GetLLVMType(BfTypeCode typeCode, bool& isSigned); llvm::Type* GetLLVMType(BfTypeCode typeCode, bool& isSigned);
BfIRTypeEntry& GetTypeEntry(int typeId); BfIRTypeEntry& GetTypeEntry(int typeId);