[cfe-commits] r121378 - in /cfe/trunk: lib/Basic/FileManager.cpp lib/Driver/ToolChains.cpp lib/Frontend/CompilerInstance.cpp lib/Lex/PTHLexer.cpp lib/Serialization/ASTReader.cpp tools/driver/cc1as_main.cpp tools/driver/driver.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Thu Dec 9 09:36:38 PST 2010
Author: mspencer
Date: Thu Dec 9 11:36:38 2010
New Revision: 121378
URL: http://llvm.org/viewvc/llvm-project?rev=121378&view=rev
Log:
Use error_code instead of std::string* for MemoryBuffer.
Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/tools/driver/cc1as_main.cpp
cfe/trunk/tools/driver/driver.cpp
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Thu Dec 9 11:36:38 2010
@@ -24,6 +24,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/system_error.h"
#include "llvm/Config/config.h"
#include <map>
#include <set>
@@ -400,13 +401,16 @@
llvm::MemoryBuffer *FileManager::
getBufferForFile(const FileEntry *Entry, std::string *ErrorStr) {
+ llvm::error_code ec;
if (FileSystemOpts.WorkingDir.empty()) {
const char *Filename = Entry->getName();
// If the file is already open, use the open file descriptor.
if (Entry->FD != -1) {
llvm::MemoryBuffer *Buf =
- llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, ErrorStr,
+ llvm::MemoryBuffer::getOpenFile(Entry->FD, Filename, ec,
Entry->getSize());
+ if (Buf == 0 && ErrorStr)
+ *ErrorStr = ec.message();
// getOpenFile will have closed the file descriptor, don't reuse or
// reclose it.
Entry->FD = -1;
@@ -414,23 +418,38 @@
}
// Otherwise, open the file.
- return llvm::MemoryBuffer::getFile(Filename, ErrorStr, Entry->getSize());
+ llvm::MemoryBuffer *res =
+ llvm::MemoryBuffer::getFile(Filename, ec, Entry->getSize());
+ if (res == 0 && ErrorStr)
+ *ErrorStr = ec.message();
+ return res;
}
llvm::sys::Path FilePath(Entry->getName());
FixupRelativePath(FilePath, FileSystemOpts);
- return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr,
- Entry->getSize());
+ llvm::MemoryBuffer *res =
+ llvm::MemoryBuffer::getFile(FilePath.c_str(), ec, Entry->getSize());
+ if (res == 0 && ErrorStr)
+ *ErrorStr = ec.message();
+ return res;
}
llvm::MemoryBuffer *FileManager::
getBufferForFile(llvm::StringRef Filename, std::string *ErrorStr) {
- if (FileSystemOpts.WorkingDir.empty())
- return llvm::MemoryBuffer::getFile(Filename, ErrorStr);
-
+ llvm::error_code ec;
+ if (FileSystemOpts.WorkingDir.empty()) {
+ llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(Filename, ec);
+ if (res == 0 && ErrorStr)
+ *ErrorStr = ec.message();
+ return res;
+ }
+
llvm::sys::Path FilePath(Filename);
FixupRelativePath(FilePath, FileSystemOpts);
- return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr);
+ llvm::MemoryBuffer *res = llvm::MemoryBuffer::getFile(FilePath.c_str(), ec);
+ if (res == 0 && ErrorStr)
+ *ErrorStr = ec.message();
+ return res;
}
/// getStatValue - Get the 'stat' information for the specified path, using the
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Dec 9 11:36:38 2010
@@ -26,6 +26,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/system_error.h"
#include <cstdlib> // ::getenv
@@ -1243,8 +1244,9 @@
}
static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) {
+ llvm::error_code ec;
llvm::OwningPtr<const llvm::MemoryBuffer>
- LsbRelease(llvm::MemoryBuffer::getFile("/etc/lsb-release"));
+ LsbRelease(llvm::MemoryBuffer::getFile("/etc/lsb-release", ec));
if (LsbRelease) {
llvm::StringRef Data = LsbRelease.get()->getBuffer();
llvm::SmallVector<llvm::StringRef, 8> Lines;
@@ -1263,7 +1265,7 @@
}
llvm::OwningPtr<const llvm::MemoryBuffer>
- RHRelease(llvm::MemoryBuffer::getFile("/etc/redhat-release"));
+ RHRelease(llvm::MemoryBuffer::getFile("/etc/redhat-release", ec));
if (RHRelease) {
llvm::StringRef Data = RHRelease.get()->getBuffer();
if (Data.startswith("Fedora release 14 (Laughlin)"))
@@ -1274,7 +1276,7 @@
}
llvm::OwningPtr<const llvm::MemoryBuffer>
- DebianVersion(llvm::MemoryBuffer::getFile("/etc/debian_version"));
+ DebianVersion(llvm::MemoryBuffer::getFile("/etc/debian_version", ec));
if (DebianVersion) {
llvm::StringRef Data = DebianVersion.get()->getBuffer();
if (Data[0] == '5')
@@ -1285,7 +1287,7 @@
}
llvm::OwningPtr<const llvm::MemoryBuffer>
- SuseRelease(llvm::MemoryBuffer::getFile("/etc/SuSE-release"));
+ SuseRelease(llvm::MemoryBuffer::getFile("/etc/SuSE-release", ec));
if (SuseRelease) {
llvm::StringRef Data = SuseRelease.get()->getBuffer();
if (Data.startswith("openSUSE 11.3"))
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Dec 9 11:36:38 2010
@@ -36,6 +36,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/system_error.h"
using namespace clang;
CompilerInstance::CompilerInstance()
@@ -486,8 +487,10 @@
}
SourceMgr.createMainFileID(File);
} else {
- llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
+ llvm::error_code ec;
+ llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN(ec);
if (!SB) {
+ // FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Thu Dec 9 11:36:38 2010
@@ -26,6 +26,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/system_error.h"
using namespace clang;
using namespace clang::io;
@@ -436,9 +437,12 @@
PTHManager *PTHManager::Create(const std::string &file, Diagnostic &Diags) {
// Memory map the PTH file.
- llvm::OwningPtr<llvm::MemoryBuffer> File(llvm::MemoryBuffer::getFile(file));
+ llvm::error_code ec;
+ llvm::OwningPtr<llvm::MemoryBuffer> File(
+ llvm::MemoryBuffer::getFile(file, ec));
if (!File) {
+ // FIXME: Add ec.message() to this diag.
Diags.Report(diag::err_invalid_pth_file) << file;
return 0;
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Dec 9 11:36:38 2010
@@ -41,6 +41,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/system_error.h"
#include <algorithm>
#include <iterator>
#include <cstdio>
@@ -2275,9 +2276,12 @@
//
// FIXME: This shouldn't be here, we should just take a raw_ostream.
std::string ErrStr;
- if (FileName == "-")
- F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(&ErrStr));
- else
+ llvm::error_code ec;
+ if (FileName == "-") {
+ F.Buffer.reset(llvm::MemoryBuffer::getSTDIN(ec));
+ if (ec)
+ ErrStr = ec.message();
+ } else
F.Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrStr));
if (!F.Buffer) {
Error(ErrStr.c_str());
Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Thu Dec 9 11:36:38 2010
@@ -42,6 +42,7 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/system_error.h"
#include "llvm/Target/TargetAsmBackend.h"
#include "llvm/Target/TargetAsmParser.h"
#include "llvm/Target/TargetData.h"
@@ -224,8 +225,10 @@
return false;
}
- MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(Opts.InputFile, &Error);
+ error_code ec;
+ MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(Opts.InputFile, ec);
if (Buffer == 0) {
+ Error = ec.message();
Diags.Report(diag::err_fe_error_reading) << Opts.InputFile;
return false;
}
Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=121378&r1=121377&r2=121378&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Thu Dec 9 11:36:38 2010
@@ -33,6 +33,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/system_error.h"
using namespace clang;
using namespace clang::driver;
@@ -181,7 +182,8 @@
llvm::SmallVectorImpl<const char*> &ArgVector,
std::set<std::string> &SavedStrings) {
const char *FName = Arg + 1;
- llvm::MemoryBuffer *MemBuf = llvm::MemoryBuffer::getFile(FName);
+ llvm::error_code ec;
+ llvm::MemoryBuffer *MemBuf = llvm::MemoryBuffer::getFile(FName, ec);
if (!MemBuf) {
ArgVector.push_back(SaveStringInSet(SavedStrings, Arg));
return;
More information about the cfe-commits
mailing list