mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
FixGEP for const geps
This commit is contained in:
parent
a7183ad803
commit
9ce7a535b4
2 changed files with 28 additions and 2 deletions
|
@ -873,7 +873,8 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry,
|
||||||
llvm::Value* gepArgs[] = {
|
llvm::Value* gepArgs[] = {
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx0),
|
llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx0),
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx1)};
|
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;
|
return;
|
||||||
}
|
}
|
||||||
else if (constType == BfConstType_ExtractValue)
|
else if (constType == BfConstType_ExtractValue)
|
||||||
|
@ -882,7 +883,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry,
|
||||||
CMD_PARAM(int, idx0);
|
CMD_PARAM(int, idx0);
|
||||||
unsigned int gepArgs[] = {
|
unsigned int gepArgs[] = {
|
||||||
(unsigned int)idx0 };
|
(unsigned int)idx0 };
|
||||||
llvmValue = llvm::ConstantExpr::getExtractValue(target, gepArgs);
|
llvmValue = FixGEP(target, llvm::ConstantExpr::getExtractValue(target, gepArgs));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (constType == BfConstType_PtrToInt)
|
else if (constType == BfConstType_PtrToInt)
|
||||||
|
|
|
@ -4,6 +4,10 @@ namespace Tests
|
||||||
{
|
{
|
||||||
class Globals
|
class Globals
|
||||||
{
|
{
|
||||||
|
public struct StructA : this(int64 a, int32 b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static int sVal0 = 123;
|
static int sVal0 = 123;
|
||||||
static int sVal1 = 234;
|
static int sVal1 = 234;
|
||||||
static int sVal2 = 345;
|
static int sVal2 = 345;
|
||||||
|
@ -16,6 +20,12 @@ namespace Tests
|
||||||
public const int*[3][2] cValsInt = .((&sVal0, &sVal1), (&sVal2, ), );
|
public const int*[3][2] cValsInt = .((&sVal0, &sVal1), (&sVal2, ), );
|
||||||
public static int*[3][2] sValsInt = .((&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]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -43,6 +53,21 @@ namespace Tests
|
||||||
Test.Assert(*(cValsInt[0][1]) == 234);
|
Test.Assert(*(cValsInt[0][1]) == 234);
|
||||||
Test.Assert(*(cValsInt[1][0]) == 345);
|
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];
|
const int* iPtr = cValsInt[2][0];
|
||||||
Test.Assert(iPtr == null);
|
Test.Assert(iPtr == null);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue