EmptyFS FS;
// Build and run Preprocessor over the preamble.
ParseInputs PI;
+ // Memory buffers below expect null-terminated && non-null strings. So make
+ // sure to always use PI.Contents!
PI.Contents = Contents.str();
PI.TFS = &FS;
PI.CompileCommand = Cmd;
// twice. However, it's important to precisely follow the preamble bounds used
// elsewhere.
auto Bounds = ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
- auto PreambleContents =
- llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size));
+ auto PreambleContents = llvm::MemoryBuffer::getMemBufferCopy(
+ llvm::StringRef(PI.Contents).take_front(Bounds.Size));
auto Clang = prepareCompilerInstance(
std::move(CI), nullptr, std::move(PreambleContents),
// Provide an empty FS to prevent preprocessor from performing IO. This
// whole preamble, which is terribly slow.
// - If scanning for Modified fails, cannot figure out newly added ones so
// there's nothing to do but generate an empty patch.
- auto BaselineScan = scanPreamble(
- // Contents needs to be null-terminated.
- Baseline.Preamble.getContents(), Modified.CompileCommand);
+ auto BaselineScan =
+ scanPreamble(Baseline.Preamble.getContents(), Modified.CompileCommand);
if (!BaselineScan) {
elog("Failed to scan baseline of {0}: {1}", FileName,
BaselineScan.takeError());