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

Fixed "over-aligned" issue with global variables

This commit is contained in:
Brian Fiete 2025-05-12 15:47:25 +02:00
parent 2f6d9e03ab
commit 8102de259f
2 changed files with 28 additions and 0 deletions

View file

@ -552,6 +552,31 @@ void BfIRCodeGen::FixValues(llvm::StructType* structType, llvm::SmallVector<llvm
}
}
void BfIRCodeGen::FixValues(llvm::StructType* structType, llvm::SmallVector<llvm::Constant*, 8>& values)
{
if (values.size() >= structType->getNumElements())
return;
int readIdx = (int)values.size() - 1;
values.resize(structType->getNumElements());
for (int i = (int)values.size() - 1; i >= 0; i--)
{
if (values[readIdx]->getType() == structType->getElementType(i))
{
values[i] = values[readIdx];
readIdx--;
}
else if (structType->getElementType(i)->isArrayTy())
{
values[i] = llvm::ConstantAggregateZero::get(structType->getElementType(i));
}
else
{
BF_FATAL("Malformed structure values");
}
}
}
void BfIRCodeGen::FixIndexer(llvm::Value*& val)
{
if ((int)val->getType()->getScalarSizeInBits() > mPtrSize * 8)
@ -1285,6 +1310,8 @@ void BfIRCodeGen::Read(BfIRTypedValue& typedValue, BfIRCodeGenEntry** codeGenEnt
}
else if (auto structType = llvm::dyn_cast<llvm::StructType>(type->mLLVMType))
{
FixValues(structType, values);
for (int i = 0; i < (int)values.size(); i++)
{
if (values[i]->getType() != structType->getElementType(i))

View file

@ -178,6 +178,7 @@ public:
public:
void InitTarget();
void FixValues(llvm::StructType* structType, llvm::SmallVector<llvm::Value*, 8>& values);
void FixValues(llvm::StructType* structType, llvm::SmallVector<llvm::Constant*, 8>& values);
void FixIndexer(llvm::Value*& val);
void FixTypedValue(BfIRTypedValue& typedValue);
BfTypeCode GetTypeCode(llvm::Type* type, bool isSigned);