r188178 - SourceManager intialization tweaks.
Benjamin Kramer
benny.kra at googlemail.com
Mon Aug 12 06:46:52 PDT 2013
Author: d0k
Date: Mon Aug 12 08:46:52 2013
New Revision: 188178
URL: http://llvm.org/viewvc/llvm-project?rev=188178&view=rev
Log:
SourceManager intialization tweaks.
- Open files before calling stat on them.
- Go through FileManager for getting the buffer of named pipes. It has the
necessary plumbing to deal with "volatile" files.
- Print the cause when stdin reading fails. The only case I can imagine where
this happens is when stdin is wired to a device file, so no test case.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/lib/Frontend/CompilerInstance.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=188178&r1=188177&r2=188178&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Mon Aug 12 08:46:52 2013
@@ -11,7 +11,7 @@ let Component = "Frontend" in {
def err_fe_error_opening : Error<"error opening '%0': %1">;
def err_fe_error_reading : Error<"error reading '%0'">;
-def err_fe_error_reading_stdin : Error<"error reading stdin">;
+def err_fe_error_reading_stdin : Error<"error reading stdin: %0">;
def err_fe_error_backend : Error<"error in backend: %0">, DefaultFatal;
// Error generated by the backend.
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=188178&r1=188177&r2=188178&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon Aug 12 08:46:52 2013
@@ -618,7 +618,7 @@ bool CompilerInstance::InitializeSourceM
// Figure out where to get and map in the main file.
if (InputFile != "-") {
- const FileEntry *File = FileMgr.getFile(InputFile);
+ const FileEntry *File = FileMgr.getFile(InputFile, /*OpenFile=*/true);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
@@ -626,26 +626,27 @@ bool CompilerInstance::InitializeSourceM
// The natural SourceManager infrastructure can't currently handle named
// pipes, but we would at least like to accept them for the main
- // file. Detect them here, read them with the more generic MemoryBuffer
- // function, and simply override their contents as we do for STDIN.
+ // file. Detect them here, read them with the volatile flag so FileMgr will
+ // pick up the correct size, and simply override their contents as we do for
+ // STDIN.
if (File->isNamedPipe()) {
- OwningPtr<llvm::MemoryBuffer> MB;
- if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) {
- Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message();
+ std::string ErrorStr;
+ if (llvm::MemoryBuffer *MB =
+ FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true)) {
+ // Create a new virtual file that will have the correct size.
+ File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
+ SourceMgr.overrideFileContents(File, MB);
+ } else {
+ Diags.Report(diag::err_cannot_open_file) << InputFile << ErrorStr;
return false;
}
-
- // Create a new virtual file that will have the correct size.
- File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
- SourceMgr.overrideFileContents(File, MB.take());
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
- if (llvm::MemoryBuffer::getSTDIN(SB)) {
- // FIXME: Give ec.message() in this diag.
- Diags.Report(diag::err_fe_error_reading_stdin);
+ if (llvm::error_code ec = llvm::MemoryBuffer::getSTDIN(SB)) {
+ Diags.Report(diag::err_fe_error_reading_stdin) << ec.message();
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
More information about the cfe-commits
mailing list