From 8102de259f6226f337a97d56c20be755a67a8f6e Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 12 May 2025 15:47:25 +0200 Subject: [PATCH] Fixed "over-aligned" issue with global variables --- IDEHelper/Compiler/BfIRCodeGen.cpp | 27 +++++++++++++++++++++++++++ IDEHelper/Compiler/BfIRCodeGen.h | 1 + 2 files changed, 28 insertions(+) diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index 0a227cf4..4531ad2e 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -552,6 +552,31 @@ void BfIRCodeGen::FixValues(llvm::StructType* structType, llvm::SmallVector& 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(type->mLLVMType)) { + FixValues(structType, values); + for (int i = 0; i < (int)values.size(); i++) { if (values[i]->getType() != structType->getElementType(i)) diff --git a/IDEHelper/Compiler/BfIRCodeGen.h b/IDEHelper/Compiler/BfIRCodeGen.h index 2b20e8f8..e3afce84 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.h +++ b/IDEHelper/Compiler/BfIRCodeGen.h @@ -178,6 +178,7 @@ public: public: void InitTarget(); void FixValues(llvm::StructType* structType, llvm::SmallVector& values); + void FixValues(llvm::StructType* structType, llvm::SmallVector& values); void FixIndexer(llvm::Value*& val); void FixTypedValue(BfIRTypedValue& typedValue); BfTypeCode GetTypeCode(llvm::Type* type, bool isSigned);