[cfe-commits] r97296 - in /cfe/trunk: include/clang-c/Index.h lib/Frontend/ASTUnit.cpp lib/Frontend/InitPreprocessor.cpp tools/CIndex/CIndex.cpp
Douglas Gregor
dgregor at apple.com
Fri Feb 26 17:32:48 PST 2010
Author: dgregor
Date: Fri Feb 26 19:32:48 2010
New Revision: 97296
URL: http://llvm.org/viewvc/llvm-project?rev=97296&view=rev
Log:
When given unsaved files in clang_createTranslationUnitFromSourceFile,
copy the source buffers provided rather than referencing them
directly, so that the caller can free those buffers immediately after
calling clang_createTranslationUnitFromSourceFile(). Otherwise, we
risk hitting those buffers later (when building source ranges, forming
diagnostics, etc.).
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/tools/CIndex/CIndex.cpp
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=97296&r1=97295&r2=97296&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Feb 26 19:32:48 2010
@@ -87,14 +87,12 @@
const char *Filename;
/**
- * \brief A null-terminated buffer containing the unsaved contents
- * of this file.
+ * \brief A buffer containing the unsaved contents of this file.
*/
const char *Contents;
/**
- * \brief The length of the unsaved contents of this buffer, not
- * counting the NULL at the end of the buffer.
+ * \brief The length of the unsaved contents of this buffer.
*/
unsigned long Length;
};
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=97296&r1=97295&r2=97296&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Feb 26 19:32:48 2010
@@ -162,6 +162,7 @@
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< RemappedFiles[I].first;
+ delete RemappedFiles[I].second;
continue;
}
Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=97296&r1=97295&r2=97296&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Fri Feb 26 19:32:48 2010
@@ -439,6 +439,7 @@
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
+ delete Remap->second;
continue;
}
@@ -477,7 +478,7 @@
= llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
if (!Buffer) {
Diags.Report(diag::err_fe_error_opening)
- << Remap->second << ErrorStr;
+ << Remap->second << ErrorStr;
continue;
}
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=97296&r1=97295&r2=97296&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Fri Feb 26 19:32:48 2010
@@ -966,7 +966,7 @@
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
for (unsigned I = 0; I != num_unsaved_files; ++I) {
const llvm::MemoryBuffer *Buffer
- = llvm::MemoryBuffer::getMemBuffer(unsaved_files[I].Contents,
+ = llvm::MemoryBuffer::getMemBufferCopy(unsaved_files[I].Contents,
unsaved_files[I].Contents + unsaved_files[I].Length,
unsaved_files[I].Filename);
RemappedFiles.push_back(std::make_pair(unsaved_files[I].Filename,
More information about the cfe-commits
mailing list