[llvm-dev] Null pointer reference in llvm::MachineOperand::print

Joshua Gerrard via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 3 00:42:43 PST 2015


First of all the code in question:

void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
                           const TargetRegisterInfo *TRI) const {

    ...

    case MachineOperand::MO_RegisterMask: {
        unsigned NumRegsInMask = 0;
        unsigned NumRegsEmitted = 0;
        OS << "<regmask";
        for (unsigned i = 0; i < TRI->getNumRegs(); ++i) {

    ...

}

This looks innocent enough, but this is in turn called by:

void MachineOperand::print(raw_ostream &OS,
                           const TargetRegisterInfo *TRI) const {
    ModuleSlotTracker DummyMST(nullptr);
    print(OS, DummyMST, TRI);
}

and:

inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
    MO.print(OS, nullptr);
    return OS;
}

Notice the nullptr as the const TargetRegisterInfo* argument.
As a result, when TRI->getNumRegs() gets called later on, we get a nullptr
dereference.

There seems to be a couple of couple of possibilities here:
a) The wrong case in the switch has been selected due to a bug elsewhere
b) The case in question should be checking for a nullptr

I encountered this whilst iterating through instructions in a
MachineBasicBlock.
Does anybody have any insight?

--
Joshua Gerrard
JUCE Software Developer

*ROLI’s **award-winning*
<http://www.telegraph.co.uk/luxury/design/31520/the-seaboard-grand-piano-wins-designs-of-the-year-2014-award.html>*
Seaboard
GRAND, celebrated as the “**piano of the future*
<http://edition.cnn.com/2013/09/27/tech/innovation/hans-zimmer-seaboard-future-piano/>*”,
is now joined by the **Seaboard RISE*
<https://www.youtube.com/watch?v=fGr7VbDiRNw>*, “**every bit as slimline
and attractive as its bigger brother*
<http://www.soundonsound.com/news?NewsID=18726>*”. The press is hailing the
Seaboard RISE as “**innovative*
<http://www.wired.co.uk/news/archive/2015-09/10/seaboard-rise-digital-keyboard-launch-uk-price>*”,
“**expressive*
<http://createdigitalmusic.com/2015/09/new-roli-instrument-wants-make-expressive-control-mainstream/>*”,
“**accessible*
<http://createdigitalmusic.com/2015/09/new-roli-instrument-wants-make-expressive-control-mainstream/>*”,
and “**a keyboard controller that does to piano keys what 3D touch does to
the iPhone*
<http://www.slashgear.com/roli-seaboard-rise-is-like-3d-touch-for-musicians-11404216/>*”.
Now available for preorder at **www.roli.com* <http://www.roli.com/>*.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151203/ab3425a2/attachment.html>


More information about the llvm-dev mailing list