[Support][MemBuffer] Prevent UB on empty StringRefs
Empty StringRefs are usually identified by their length being zero, and sometimes they'll have Data==nullptr (e.g. default constructed, or derived from an operation like split/copy and result turned out to be empty). If such StringRef objects are passed to llvm::MemoryBuffer::getMemBufferCopy, it'll result in UB as neither src nor dst can be null, even if size is zero. This patch prevents that UB by not issuing a copy whenever StringRef is empty. Differential Revision: https://reviews.llvm.org/D144706
Loading
Please sign in to comment