From 621fe99882c28038e8ce313ec6597256a59496e0 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 22 Jan 2021 16:46:52 -0800 Subject: [PATCH] undef detection --- IDEHelper/Compiler/CeMachine.cpp | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index 649a48e9..ee8610d1 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -3697,11 +3697,22 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns //SetAndRestoreValue prevMethodStateInConstEval(module->mCurMethodState, NULL); if (mCeMachine->mAppendAllocInfo != NULL) - { - if ((mCeMachine->mAppendAllocInfo->mAppendSizeValue) && (!mCeMachine->mAppendAllocInfo->mAppendSizeValue.IsConst())) + { + if (mCeMachine->mAppendAllocInfo->mAppendSizeValue) { - Fail("Non-constant append alloc"); - return BfTypedValue(); + bool isConst = mCeMachine->mAppendAllocInfo->mAppendSizeValue.IsConst(); + if (isConst) + { + auto constant = module->mBfIRBuilder->GetConstant(mCeMachine->mAppendAllocInfo->mAppendSizeValue); + if (constant->mConstType == BfConstType_Undef) + isConst = false; + } + + if (!isConst) + { + Fail("Non-constant append alloc"); + return BfTypedValue(); + } } } @@ -3737,13 +3748,20 @@ BfTypedValue CeContext::Call(BfAstNode* targetSrc, BfModule* module, BfMethodIns break; } if (paramType->IsComposite()) - { - auto paramTypeInst = paramType->ToTypeInstance(); - paramCompositeSize += paramTypeInst->mInstSize; + { + paramCompositeSize += paramType->mSize; } auto arg = args[argIdx]; - if (!arg.IsConst()) + bool isConst = arg.IsConst(); + if (isConst) + { + auto constant = module->mBfIRBuilder->GetConstant(arg); + if (constant->mConstType == BfConstType_Undef) + isConst = false; + } + + if (!isConst) { if ((argIdx != thisArgIdx) && (argIdx != appendAllocIdx)) {