Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more alloc-dealloc mismatches and use-after-scopes #55420

Merged
7 commits merged into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3543,6 +3543,7 @@ int LinearScan::BuildReturn(GenTree* tree)
noway_assert(op1->IsMultiRegCall() || op1->IsMultiRegLclVar());

int srcCount;
ReturnTypeDesc nonCallRetTypeDesc;
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
const ReturnTypeDesc* pRetTypeDesc;
if (op1->OperIs(GT_CALL))
{
Expand All @@ -3552,12 +3553,11 @@ int LinearScan::BuildReturn(GenTree* tree)
{
assert(compiler->lvaEnregMultiRegVars);
LclVarDsc* varDsc = compiler->lvaGetDesc(op1->AsLclVar()->GetLclNum());
ReturnTypeDesc retTypeDesc;
retTypeDesc.InitializeStructReturnType(compiler, varDsc->GetStructHnd(),
nonCallRetTypeDesc.InitializeStructReturnType(compiler, varDsc->GetStructHnd(),
compiler->info.compCallConv);
pRetTypeDesc = &retTypeDesc;
pRetTypeDesc = &nonCallRetTypeDesc;
assert(compiler->lvaGetDesc(op1->AsLclVar()->GetLclNum())->lvFieldCnt ==
retTypeDesc.GetReturnRegCount());
nonCallRetTypeDesc.GetReturnRegCount());
}
srcCount = pRetTypeDesc->GetReturnRegCount();
// For any source that's coming from a different register file, we need to ensure that
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/vm/threadstatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void ThreadLocalBlock::FreeTable()
SpinLock::Holder lock(&m_TLMTableLock);

// Free the table itself
delete m_pTLMTable;
delete[] m_pTLMTable;
m_pTLMTable = NULL;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ void ThreadLocalBlock::EnsureModuleIndex(ModuleIndex index)

// If this allocation fails, we will throw. If it succeeds,
// then we are good to go
PTR_TLMTableEntry pNewModuleSlots = (PTR_TLMTableEntry) (void*) new BYTE[sizeof(TLMTableEntry) * aModuleIndices];
PTR_TLMTableEntry pNewModuleSlots = (PTR_TLMTableEntry) new TLMTableEntry[aModuleIndices];
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved

// Zero out the new TLM table
memset(pNewModuleSlots, 0 , sizeof(TLMTableEntry) * aModuleIndices);
Expand Down Expand Up @@ -704,9 +704,7 @@ PTR_ThreadLocalModule ThreadStatics::AllocateTLM(Module * pModule)

SIZE_T size = pModule->GetThreadLocalModuleSize();

_ASSERTE(size >= ThreadLocalModule::OffsetOfDataBlob());

PTR_ThreadLocalModule pThreadLocalModule = (ThreadLocalModule*)new BYTE[size];
PTR_ThreadLocalModule pThreadLocalModule = new({ pModule }) ThreadLocalModule;

// We guarantee alignment for 64-bit regular thread statics on 32-bit platforms even without FEATURE_64BIT_ALIGNMENT for performance reasons.

Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/vm/threadstatics.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,20 @@ struct ThreadLocalModule
return GetPrecomputedStaticsClassData()[classID] & ClassInitFlags::INITIALIZED_FLAG;
}

void* operator new(SIZE_T) = delete;

struct ParentModule { PTR_Module pModule; };

void* operator new(SIZE_T baseSize, ParentModule parentModule)
{
SIZE_T size = parentModule.pModule->GetThreadLocalModuleSize();

_ASSERTE(size >= baseSize);
_ASSERTE(size >= ThreadLocalModule::OffsetOfDataBlob());

return ::operator new(size);
}

#ifndef DACCESS_COMPILE

FORCEINLINE void EnsureClassAllocated(MethodTable * pMT)
Expand Down