From fe2244fb4b6f3a8234b3c4529e4bbb0351da0deb Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 16 Mar 2024 18:34:21 -0400 Subject: [PATCH] Fixed CeMachine::GetFunction with __INLINE methods --- IDEHelper/Compiler/BfModule.cpp | 13 ++++++++++++ IDEHelper/Compiler/BfModuleTypeUtils.cpp | 2 +- IDEHelper/Compiler/CeMachine.cpp | 27 ++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 72ce6904..08ed17d2 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -12002,6 +12002,12 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con else { auto wantTypeInst = wantType->ToTypeInstance(); + if (wantTypeInst == NULL) + { + InternalError("BfModule::ConstantToCurrent typeInst error"); + return BfIRValue(); + } + if (wantTypeInst->mBaseType != NULL) { auto baseVal = ConstantToCurrent(constHolder->GetConstant(constArray->mValues[0]), constHolder, wantTypeInst->mBaseType); @@ -12024,6 +12030,13 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con { if (fieldInstance.mDataIdx < 0) continue; + + if (fieldInstance.mDataIdx >= constArray->mValues.mSize) + { + InternalError("BfModule::ConstantToCurrent union error"); + return BfIRValue(); + } + auto val = constArray->mValues[fieldInstance.mDataIdx]; BfIRValue memberVal = ConstantToCurrent(constHolder->GetConstant(val), constHolder, fieldInstance.mResolvedType); if (fieldInstance.mDataIdx == newVals.mSize) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index fcacdd08..f683a4d0 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -6268,7 +6268,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (!typeInstance->IsInterface()) { auto interfaceTypeDef = checkInterface->mTypeDef; - BF_ASSERT(interfaceTypeDef->mMethods.size() == checkInterface->mMethodInstanceGroups.size()); + BF_ASSERT((interfaceTypeDef->mMethods.size() == checkInterface->mMethodInstanceGroups.size()) || (checkInterface->IsDeleting())); // Reserve empty entries for (int methodIdx = 0; methodIdx < (int)interfaceTypeDef->mMethods.size(); methodIdx++) diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index e4ec9928..adbd3768 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -11,6 +11,7 @@ #include "../Backend/BeIRCodeGen.h" #include "BeefySysLib/platform/PlatformHelper.h" #include "../DebugManager.h" +#include "BeefySysLib/util/StackHelper.h" extern "C" { @@ -5051,6 +5052,24 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod // DISABLED //return BfTypedValue(); + // + { + StackHelper stackHelper; + if (!stackHelper.CanStackExpand(256 * 1024)) + { + BfTypedValue result; + if (!stackHelper.Execute([&]() + { + result = Call(callSource, module, methodInstance, args, flags, expectingType); + })) + { + module->Fail("Stack exhausted in CeContext::Call", callSource.mRefNode); + } + return result; + } + } + + AutoTimer autoTimer(mCeMachine->mRevisionExecuteTime); SetAndRestoreValue curPrevContext(mPrevContext, mCeMachine->mCurContext); @@ -9990,11 +10009,15 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f if (auto function = BeValueDynCast(funcVal)) { + String funcName = function->mName; + if (funcName.EndsWith("__INLINE")) + funcName.RemoveFromEnd(8); + CeFunctionInfo** namedFunctionInfoPtr = NULL; - if (mNamedFunctionMap.TryAdd(function->mName, NULL, &namedFunctionInfoPtr)) + if (mNamedFunctionMap.TryAdd(funcName, NULL, &namedFunctionInfoPtr)) { ceFunctionInfo = new CeFunctionInfo(); - ceFunctionInfo->mName = function->mName; + ceFunctionInfo->mName = funcName; *namedFunctionInfoPtr = ceFunctionInfo; } else