diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index 06799093..785af0b8 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -873,7 +873,8 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, llvm::Value* gepArgs[] = { llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx0), llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx1)}; - llvmValue = llvm::ConstantExpr::getInBoundsGetElementPtr(NULL, target, gepArgs); + + llvmValue = FixGEP(target, llvm::ConstantExpr::getInBoundsGetElementPtr(NULL, target, gepArgs)); return; } else if (constType == BfConstType_ExtractValue) @@ -882,7 +883,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, CMD_PARAM(int, idx0); unsigned int gepArgs[] = { (unsigned int)idx0 }; - llvmValue = llvm::ConstantExpr::getExtractValue(target, gepArgs); + llvmValue = FixGEP(target, llvm::ConstantExpr::getExtractValue(target, gepArgs)); return; } else if (constType == BfConstType_PtrToInt) diff --git a/IDEHelper/Tests/src/Globals.bf b/IDEHelper/Tests/src/Globals.bf index 5fd557ce..b2eac727 100644 --- a/IDEHelper/Tests/src/Globals.bf +++ b/IDEHelper/Tests/src/Globals.bf @@ -4,6 +4,10 @@ namespace Tests { class Globals { + public struct StructA : this(int64 a, int32 b) + { + } + static int sVal0 = 123; static int sVal1 = 234; static int sVal2 = 345; @@ -16,6 +20,12 @@ namespace Tests public const int*[3][2] cValsInt = .((&sVal0, &sVal1), (&sVal2, ), ); public static int*[3][2] sValsInt = .((&sVal0, &sVal1), (&sVal2, ), ); + public const StructA[2] cValsStruct = .(.(1, 2), .(3, 4)); + public static StructA[2] sValsStruct = .(.(1, 2), .(3, 4)); + + public const StructA cValStruct = cValsStruct[0]; + public static StructA sValStruct = sValsStruct[0]; + [Test] public static void TestBasics() { @@ -43,6 +53,21 @@ namespace Tests Test.Assert(*(cValsInt[0][1]) == 234); Test.Assert(*(cValsInt[1][0]) == 345); + Test.Assert(cValsStruct[0].a == 1); + Test.Assert(cValsStruct[0].b == 2); + Test.Assert(cValsStruct[1].a == 3); + Test.Assert(cValsStruct[1].b == 4); + + Test.Assert(sValsStruct[0].a == 1); + Test.Assert(sValsStruct[0].b == 2); + Test.Assert(sValsStruct[1].a == 3); + Test.Assert(sValsStruct[1].b == 4); + + Test.Assert(cValStruct.a == 1); + Test.Assert(cValStruct.b == 2); + Test.Assert(sValStruct.a == 1); + Test.Assert(sValStruct.b == 2); + const int* iPtr = cValsInt[2][0]; Test.Assert(iPtr == null);