ymandel created this revision. ymandel added a reviewer: alexfh. Herald added a subscriber: cfe-commits.
`buildASTFromCodeWithArgs()` was creating a memory buffer referencing a stack-allocated string. This diff changes the implementation to copy the code string into the memory buffer so that said buffer owns the memory. Repository: rC Clang https://reviews.llvm.org/D55765 Files: lib/Tooling/Tooling.cpp Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -603,9 +603,8 @@ &Action, Files.get(), std::move(PCHContainerOps)); SmallString<1024> CodeStorage; - InMemoryFileSystem->addFile(FileNameRef, 0, - llvm::MemoryBuffer::getMemBuffer( - Code.toNullTerminatedStringRef(CodeStorage))); + InMemoryFileSystem->addFile( + FileNameRef, 0, llvm::MemoryBuffer::getMemBufferCopy(Code.toStringRef())); if (!Invocation.run()) return nullptr;
Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -603,9 +603,8 @@ &Action, Files.get(), std::move(PCHContainerOps)); SmallString<1024> CodeStorage; - InMemoryFileSystem->addFile(FileNameRef, 0, - llvm::MemoryBuffer::getMemBuffer( - Code.toNullTerminatedStringRef(CodeStorage))); + InMemoryFileSystem->addFile( + FileNameRef, 0, llvm::MemoryBuffer::getMemBufferCopy(Code.toStringRef())); if (!Invocation.run()) return nullptr;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits