| 9258 | static int sValueFromExprIdx = 0; |
| 9259 | |
| 9260 | BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNullable) |
| 9261 | { |
| 9262 | auto pendingNullCond = mCurMethodState->mPendingNullConditional; |
| 9263 | |
| 9264 | if ((result) && (!result.mType->IsVar()) && (!ignoreNullable)) |
| 9265 | { |
| 9266 | auto notNullBB = mBfIRBuilder->GetInsertBlock(); |
| 9267 | |
| 9268 | //TODO: Make this work, needed for 'void' and such |
| 9269 | BfType* nullableType = NULL; |
| 9270 | if ((result.mType->IsValueType()) && (!result.mType->IsNullable())) |
| 9271 | { |
| 9272 | BfTypeVector typeVec; |
| 9273 | typeVec.push_back(result.mType); |
| 9274 | nullableType = ResolveTypeDef(mCompiler->mNullableTypeDef, typeVec); |
| 9275 | BF_ASSERT(nullableType != NULL); |
| 9276 | } |
| 9277 | |
| 9278 | // Go back to start and do any setup we need |
| 9279 | mBfIRBuilder->SetInsertPoint(pendingNullCond->mPrevBB); |
| 9280 | BfTypedValue nullableTypedValue; |
| 9281 | if (nullableType != NULL) |
| 9282 | { |
| 9283 | nullableTypedValue = BfTypedValue(CreateAlloca(nullableType, true, "nullCond.nullable"), nullableType, true); |
| 9284 | mBfIRBuilder->CreateMemSet(nullableTypedValue.mValue, GetConstValue(0, GetPrimitiveType(BfTypeCode_Int8)), |
| 9285 | GetConstValue(nullableType->mSize), nullableType->mAlign); |
| 9286 | } |
| 9287 | mBfIRBuilder->CreateBr(pendingNullCond->mCheckBB); |
| 9288 | |
| 9289 | // Now that we have the nullableTypedValue we can set that, or just jump if we didn't need it |
| 9290 | mBfIRBuilder->SetInsertPoint(notNullBB); |
| 9291 | result = LoadValue(result); |
| 9292 | if (nullableTypedValue) |
| 9293 | { |
| 9294 | auto elementType = nullableType->GetUnderlyingType(); |
| 9295 | if (elementType->IsVar()) |
| 9296 | { |
| 9297 | // Do nothing |
| 9298 | } |
| 9299 | else if (elementType->IsValuelessType()) |
| 9300 | { |
| 9301 | BfIRValue ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 1); // mHasValue |
| 9302 | mBfIRBuilder->CreateStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue); |
| 9303 | } |
| 9304 | else |
| 9305 | { |
| 9306 | BfIRValue ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 1); // mValue |
| 9307 | mBfIRBuilder->CreateAlignedStore(result.mValue, ptrValue, result.mType->mAlign); |
| 9308 | ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 2); // mHasValue |
| 9309 | mBfIRBuilder->CreateAlignedStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue, 1); |
| 9310 | } |
| 9311 | result = nullableTypedValue; |
| 9312 | } |
| 9313 | mBfIRBuilder->CreateBr(pendingNullCond->mDoneBB); |
| 9314 | |
| 9315 | AddBasicBlock(pendingNullCond->mDoneBB); |
| 9316 | if (nullableType == NULL) |
| 9317 | { |
no test coverage detected