Skip to content

Commit

Permalink
Fix uses of uninitialized data (#46965)
Browse files Browse the repository at this point in the history
* Fix uses of uninitialized data

Fixes #46961

* Fix typo

* Formatting
  • Loading branch information
BruceForstall committed Jan 15, 2021
1 parent f4ae905 commit e3247ad
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
case GT_PINVOKE_PROLOG:
noway_assert(((gcInfo.gcRegGCrefSetCur | gcInfo.gcRegByrefSetCur) & ~fullIntArgRegMask()) == 0);

#ifdef PSEUDORANDOM_NOP_INSERTION
// the runtime side requires the codegen here to be consistent
emit->emitDisableRandomNops();
#endif // PSEUDORANDOM_NOP_INSERTION
break;

case GT_LABEL:
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,8 +1793,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
case GT_PINVOKE_PROLOG:
noway_assert(((gcInfo.gcRegGCrefSetCur | gcInfo.gcRegByrefSetCur) & ~fullIntArgRegMask()) == 0);

#ifdef PSEUDORANDOM_NOP_INSERTION
// the runtime side requires the codegen here to be consistent
emit->emitDisableRandomNops();
#endif // PSEUDORANDOM_NOP_INSERTION
break;

case GT_LABEL:
Expand Down
7 changes: 6 additions & 1 deletion src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1846,10 +1846,13 @@ class emitter

unsigned emitNxtIGnum;

#ifdef PSEUDORANDOM_NOP_INSERTION

// random nop insertion to break up nop sleds
unsigned emitNextNop;
bool emitRandomNops;
void emitEnableRandomNops()

void emitEnableRandomNops()
{
emitRandomNops = true;
}
Expand All @@ -1858,6 +1861,8 @@ class emitter
emitRandomNops = false;
}

#endif // PSEUDORANDOM_NOP_INSERTION

insGroup* emitAllocAndLinkIG();
insGroup* emitAllocIG();
void emitInitIG(insGroup* ig);
Expand Down
21 changes: 11 additions & 10 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9237,18 +9237,19 @@ class MergedReturns
// Need to check both for matching const val and for genReturnBB
// because genReturnBB is used for non-constant returns and its
// corresponding entry in the returnConstants array is garbage.
if (returnConstants[i] == constVal)
{
BasicBlock* returnBlock = returnBlocks[i];
// Check the returnBlocks[] first, so we don't access an uninitialized
// returnConstants[] value (which some tools like valgrind will
// complain about).

if (returnBlock == comp->genReturnBB)
{
// This is the block used for non-constant returns, so
// its returnConstants entry is just garbage; don't be
// fooled.
continue;
}
BasicBlock* returnBlock = returnBlocks[i];

if (returnBlock == comp->genReturnBB)
{
continue;
}

if (returnConstants[i] == constVal)
{
*index = i;
return returnBlock;
}
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void CodeGen::instGen(instruction ins)
GetEmitter()->emitIns(ins);

#ifdef TARGET_XARCH
#ifdef PSEUDORANDOM_NOP_INSERTION
// A workaround necessitated by limitations of emitter
// if we are scheduled to insert a nop here, we have to delay it
// hopefully we have not missed any other prefix instructions or places
Expand All @@ -201,6 +202,7 @@ void CodeGen::instGen(instruction ins)
{
GetEmitter()->emitNextNop = 1;
}
#endif // PSEUDORANDOM_NOP_INSERTION
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,10 @@ LinearScan::LinearScan(Compiler* theCompiler)
, refPositions(theCompiler->getAllocator(CMK_LSRA_RefPosition))
, listNodePool(theCompiler)
{
firstColdLoc = MaxLocation;

#ifdef DEBUG
maxNodeLocation = 0;
firstColdLoc = MaxLocation;
activeRefPosition = nullptr;

// Get the value of the environment variable that controls stress for register allocation
Expand Down

0 comments on commit e3247ad

Please sign in to comment.