This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix uninitialized variable after call to evaluateConstantImm
ClosedPublic

Authored by thegameg on Jul 26 2019, 1:34 PM.

Details

Summary

For llvm/test/MC/RISCV/rv64i-aliases-invalid.s, UBSan reports:

lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:371:9: runtime error: load of value 3879186881, which is not a valid value for type 'RISCVMCExpr::VariantKind'
 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:371:9 in

It turns out that evaluateConstantImm does not set VK and it remains unitialized when doing comparisons in isImmXLenLI().

Diff Detail

Event Timeline

thegameg created this revision.Jul 26 2019, 1:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2019, 1:34 PM
asb accepted this revision.Jul 26 2019, 8:44 PM

This looks good to me, thanks! Upon review I considered whether evaluateConstantImm should always set VK, but it seems sensible to rely on the caller to initialise it if necessary, as setting VK when evaluateConstantImm failed seems surprising.

This revision is now accepted and ready to land.Jul 26 2019, 8:44 PM
This revision was automatically updated to reflect the committed changes.