This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Avoid overflow when determining number of nops for code align
ClosedPublic

Authored by edward-jones on Jun 13 2019, 8:00 AM.

Details

Summary

RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign() assumed that the align specified would be greater than or equal to the minimum nop length, but that is not always the case - for example if a user specifies ".align 0" in assembly.

Diff Detail

Repository
rL LLVM

Event Timeline

edward-jones created this revision.Jun 13 2019, 8:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2019, 8:00 AM
lewis-revill added inline comments.Jun 13 2019, 8:55 AM
lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
320 ↗(On Diff #204541)

Shouldn't make any functional difference but can we return false instead? Seems more prudent to say we 'shouldn't emit nops' rather than saying we should but the size should be 0?

Incorporated Lewis' suggested fix.

I realized that the use of this in shouldInsertFixupForCodeAlign() doesn't actually check the return value, and with the changes I've made here it means that shouldInsertFixupForCodeAlign() could read uninitialized memory. I've submitted a separate patch to fix that problem (D63285)

asb accepted this revision.Jun 18 2019, 3:55 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jun 18 2019, 3:55 AM
This revision was automatically updated to reflect the committed changes.