This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix downcast from nullptr
ClosedPublic

Authored by ngzhian on Apr 22 2020, 4:41 PM.

Details

Summary

getTargetStreamer() might return null (e.g. when running
inlined-strings.ll test), downcasting to a reference will be wrong. This
is detectable with -fsanitize=null.

Diff Detail

Event Timeline

ngzhian created this revision.Apr 22 2020, 4:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2020, 4:41 PM
ngzhian added a subscriber: zbrid.Apr 22 2020, 4:43 PM
jsji added a reviewer: Restricted Project.Apr 22 2020, 7:24 PM
jsji added a project: Restricted Project.

Missing test. And PPCAIXAsmPrinter::emitEndOfAsmFile also has issues if it could be null. And it seems that, we miss this check also in:

./AsmParser/PPCAsmParser.cpp:           getParser().getStreamer().getTargetStreamer());
./AsmParser/PPCAsmParser.cpp:           getParser().getStreamer().getTargetStreamer());
./AsmParser/PPCAsmParser.cpp:           getParser().getStreamer().getTargetStreamer());
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1416

null check ?

ngzhian updated this revision to Diff 259600.Apr 23 2020, 9:20 AM

Add null check

ngzhian marked an inline comment as done.Apr 23 2020, 9:21 AM

I don't have a good idea how to add test for this. With an ASAN build with -fsanitize=null, we get an error when running inlined-strings.ll.

It is better to have some tests. You can get it by adding assertion for TS and then, running the test to see if any test trigger this assertion. And please also fix this for PPCAIXAsmPrinter and PPCAsmParser together. Thank you.

ngzhian updated this revision to Diff 259964.Apr 24 2020, 12:30 PM

Add some tests for null streamer. Fix more instances of downcast from nullptr.

Thanks for the advice, Steven. I found some existing tests that exercised the particular downcasting logic, and found that if I set -filetype=null in those RUN: directives, I could trigger a crash. So I added a line to those tests. Also made the same fix to PPCAsmParser and PPCAIXAsmPrinter.

steven.zhang accepted this revision.Apr 26 2020, 6:43 PM

LGTM, thank you for the fixing.

This revision is now accepted and ready to land.Apr 26 2020, 6:43 PM

Thanks Steven, I do not have commit access, can you please help me commit this?

steven.zhang added a comment.EditedApr 28 2020, 2:08 AM

Thanks Steven, I do not have commit access, can you please help me commit this?

Sure.

This revision was automatically updated to reflect the committed changes.