Skip to content

Commit

Permalink
RISC-V: fix memory reference to work for NULL pointer
Browse files Browse the repository at this point in the history
While this is bit pathological case, some clients may use it to generate
segfault. SOMpp does this.

Signed-off-by: Jan Vrany <jan.vrany@fit.cvut.cz>
  • Loading branch information
janvrany committed Jan 30, 2020
1 parent 70a7ebd commit 147450d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions compiler/riscv/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -178,13 +178,21 @@ void OMR::RV::MemoryReference::addToOffset(TR::Node *node, intptrj_t amount, TR:

if (amount == 0)
{
if (_baseRegister == NULL)
{
_baseRegister = cg->machine()->getRealRegister(TR::RealRegister::zero);
}
return;
}

if (_baseRegister != NULL)
{
self()->consolidateRegisters(NULL, NULL, false, cg);
}
else
{
_baseRegister = cg->machine()->getRealRegister(TR::RealRegister::zero);
}

intptrj_t displacement = self()->getOffset() + amount;
if (!VALID_ITYPE_IMM(displacement))
Expand Down Expand Up @@ -382,8 +390,6 @@ void OMR::RV::MemoryReference::consolidateRegisters(TR::Register *srcReg, TR::No
{
TR::Register *tempTargetRegister;

TR_ASSERT(false, "This method needs revision");

if (self()->getUnresolvedSnippet() != NULL)
{
TR_UNIMPLEMENTED();
Expand Down

0 comments on commit 147450d

Please sign in to comment.