From 10c81963527f6afcf15908c064acda694f534ec7 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Thu, 20 May 2021 17:19:18 +0200 Subject: [PATCH 1/3] fixed thiscall compile crash now hopefully --- IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 5 ++--- IDEHelper/Tests/src/Functions.bf | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index c38c5c8f..27f74558 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -1227,8 +1227,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, { checkType = GetParamType(0); - //TODO(BCF): Breaks tests - //hasExplicitThis = true; + hasExplicitThis = true; } else checkType = GetOwner(); @@ -1236,7 +1235,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, } else { - if (hasExplicitThis) + if (hasExplicitThis && paramIdx == 0) { // We already looked at this hasExplicitThis = false; diff --git a/IDEHelper/Tests/src/Functions.bf b/IDEHelper/Tests/src/Functions.bf index 7228b7c3..a174bdd6 100644 --- a/IDEHelper/Tests/src/Functions.bf +++ b/IDEHelper/Tests/src/Functions.bf @@ -130,6 +130,22 @@ namespace Tests } } + [CRepr] + struct StructCRepr + { + public int32 something = 1; + + bool Run() => something == 1; + + public static void Test() + { + StructCRepr sc = .(); + function bool(StructCRepr this) func = => Run; + + Test.Assert(func(sc)); + } + } + public static int UseFunc0(function int (T this, float f) func, T a, float b) { return func(a, b); From 954992b9d4a677e0361045a76e6fd8b9c47b7044 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Thu, 20 May 2021 18:16:55 +0200 Subject: [PATCH 2/3] proper fix --- IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index 27f74558..581a04e7 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -1209,7 +1209,6 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, returnType = module->mBfIRBuilder->MapType(mReturnType); } - bool hasExplicitThis = false; for (int paramIdx = -1; paramIdx < GetParamCount(); paramIdx++) { BfType* checkType = NULL; @@ -1224,23 +1223,15 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, else { if (HasExplicitThis()) - { checkType = GetParamType(0); - - hasExplicitThis = true; - } else checkType = GetOwner(); } } else { - if (hasExplicitThis && paramIdx == 0) - { - // We already looked at this - hasExplicitThis = false; - continue; - } + if ((paramIdx == 0) && (mMethodDef->mHasExplicitThis)) + continue; // Skip over the explicit 'this' checkType = GetParamType(paramIdx); } @@ -1354,9 +1345,6 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, if (checkType2 != NULL) _AddType(checkType2); - - if ((paramIdx == -1) && (mMethodDef->mHasExplicitThis)) - paramIdx++; // Skip over the explicit 'this' } if ((!module->mIsComptimeModule) && (GetStructRetIdx(forceStatic) == 1)) From 7e68a366a1d1e53abb580b3559f666a7e5efb131 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Thu, 20 May 2021 18:31:44 +0200 Subject: [PATCH 3/3] actually call test --- IDEHelper/Tests/src/Functions.bf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/IDEHelper/Tests/src/Functions.bf b/IDEHelper/Tests/src/Functions.bf index a174bdd6..669c1a4a 100644 --- a/IDEHelper/Tests/src/Functions.bf +++ b/IDEHelper/Tests/src/Functions.bf @@ -198,6 +198,8 @@ namespace Tests UseFunc0(func2, sa, 100.0f); true }); + + StructCRepr.Test(); } } }