Skip to content

Commit

Permalink
Merge pull request #20877 from mpirvu/bbfix
Browse files Browse the repository at this point in the history
Prevent use of uninitialized variable
  • Loading branch information
pshipton authored Jan 2, 2025
2 parents fee2f8a + ab9f995 commit 00929cf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions runtime/compiler/optimizer/J9TransformUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,16 +2037,16 @@ J9::TransformUtil::transformIndirectLoadChainImpl(TR::Compilation *comp,
return false;
}

void *valuePtr;
J9::TransformUtil::value value;
J9::TransformUtil::value val;
void *valuePtr = NULL;
#if defined(J9VM_OPT_JITSERVER)
if (isServer)
{
// Instead of the recursive dereferenceStructPointerChain, we only consider a single level
// of indirection
void *result = dereferenceStructPointer(baseKnownObject, node, baseExpression,
isBaseStableArray, comp, &value);
valuePtr = &value;
isBaseStableArray, comp, &val);
valuePtr = &val;
if (result != valuePtr)
return false;
}
Expand Down Expand Up @@ -2114,6 +2114,7 @@ J9::TransformUtil::transformIndirectLoadChainImpl(TR::Compilation *comp,
break;
case TR::Address:
{
uintptr_t value = 0;
if (isFinalFieldPointingAtRepresentableNativeStruct(symRef, comp))
{
#if defined(J9VM_OPT_JITSERVER)
Expand All @@ -2124,8 +2125,9 @@ J9::TransformUtil::transformIndirectLoadChainImpl(TR::Compilation *comp,
{
if (changeIndirectLoadIntoConst(node, TR::loadaddr, removedNode, comp))
{
TR_OpaqueClassBlock *value = *(TR_OpaqueClassBlock**)valuePtr;
node->setSymbolReference(comp->getSymRefTab()->findOrCreateClassSymbol(comp->getMethodSymbol(), -1, value));
TR_OpaqueClassBlock *clazz = *(TR_OpaqueClassBlock**)valuePtr;
value = (uintptr_t)clazz;
node->setSymbolReference(comp->getSymRefTab()->findOrCreateClassSymbol(comp->getMethodSymbol(), -1, clazz));
}
else
{
Expand All @@ -2147,7 +2149,7 @@ J9::TransformUtil::transformIndirectLoadChainImpl(TR::Compilation *comp,
#endif /* defined(J9VM_OPT_JITSERVER) */
if (symRef->getReferenceNumber() - comp->getSymRefTab()->getNumHelperSymbols() == TR::SymbolReferenceTable::ramStaticsFromClassSymbol)
{
uintptr_t value = *(uintptr_t*)valuePtr;
value = *(uintptr_t*)valuePtr;
if (changeIndirectLoadIntoConst(node, TR::aconst, removedNode, comp))
{
node->setAddress(value);
Expand All @@ -2171,7 +2173,7 @@ J9::TransformUtil::transformIndirectLoadChainImpl(TR::Compilation *comp,
else
#endif /* defined(J9VM_OPT_JITSERVER) */
{
uintptr_t value = fej9->getReferenceFieldAtAddress((uintptr_t)valuePtr);
value = fej9->getReferenceFieldAtAddress((uintptr_t)valuePtr);
if (value)
{
knotIndex = comp->getKnownObjectTable()->getOrCreateIndexAt(&value,
Expand All @@ -2185,7 +2187,7 @@ J9::TransformUtil::transformIndirectLoadChainImpl(TR::Compilation *comp,
comp->getSymRefTab()->findOrCreateSymRefWithKnownObject(symRef, knotIndex);

if (improvedSymRef->hasKnownObjectIndex()
&& performTransformation(comp, "O^O transformIndirectLoadChain: %s [%p] with fieldOffset %d is obj%d referenceAddr is %p\n", node->getOpCode().getName(), node, improvedSymRef->getKnownObjectIndex(), symRef->getOffset(), value))
&& performTransformation(comp, "O^O transformIndirectLoadChain: %s [%p] with fieldOffset %d is obj%d referenceAddr is %p\n", node->getOpCode().getName(), node, improvedSymRef->getKnownObjectIndex(), symRef->getOffset(), (void*)value))
{
node->setSymbolReference(improvedSymRef);
node->setIsNull(false);
Expand Down

0 comments on commit 00929cf

Please sign in to comment.