Page MenuHomePhabricator

Assert on implicit truncation in llvm::endian::Writer
Needs ReviewPublic

Authored by jordan_rose on Jun 15 2018, 6:00 PM.

Details

Reviewers
pcc
zturner
Summary

llvm::endian::Writer is often used to serialize for binary formats, which makes it attractive to explicitly provide template arguments for the type being written. However, this can also lead to accidental truncation of data, which can lead to corruption of the serialized archive. (Real-world example: https://github.com/apple/swift/pull/17265.) Add assertions for this sort of accidental truncation with integer types, and for overflow errors with floating-point types, while preserving the existing behavior when the template argument is not provided explicitly.

Diff Detail

Repository
rL LLVM

Event Timeline

jordan_rose created this revision.Jun 15 2018, 6:00 PM
jordan_rose added a reviewer: zturner.