If compile unit's language is not set then don't crash while dump'ing compile unit.
[oota-llvm.git] / lib / Archive / ArchiveReader.cpp
index 529b6527075c50be1195699ae884b47a1255172d..b07e884b654796f0e01c72104eabaf917193d15d 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Reid Spencer and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Module.h"
+#include <cstdlib>
 #include <memory>
 using namespace llvm;
 
 /// Read a variable-bit-rate encoded unsigned integer
-inline unsigned readInteger(const char*&At, const char*End){
+static inline unsigned readInteger(const char*&At, const char*End) {
   unsigned Shift = 0;
   unsigned Result = 0;
 
@@ -218,8 +219,6 @@ Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
   ArchiveMember* member = new ArchiveMember(this);
 
   // Fill in fields of the ArchiveMember
-  member->next = 0;
-  member->prev = 0;
   member->parent = this;
   member->path.set(pathname);
   member->info.fileSize = MemberSize;
@@ -238,7 +237,7 @@ Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
 bool
 Archive::checkSignature(std::string* error) {
   // Check the magic string at file's header
-  if (mapfile->size() < 8 || memcmp(base, ARFILE_MAGIC, 8)) {
+  if (mapfile->getBufferSize() < 8 || memcmp(base, ARFILE_MAGIC, 8)) {
     if (error)
       *error = "invalid signature for an archive file";
     return false;
@@ -256,7 +255,7 @@ Archive::loadArchive(std::string* error) {
   members.clear();
   symTab.clear();
   const char *At = base;
-  const char *End = base + mapfile->size();
+  const char *End = mapfile->getBufferEnd();
 
   if (!checkSignature(error))
     return false;
@@ -369,7 +368,7 @@ Archive::loadSymbolTable(std::string* ErrorMsg) {
   members.clear();
   symTab.clear();
   const char *At = base;
-  const char *End = base + mapfile->size();
+  const char *End = mapfile->getBufferEnd();
 
   // Make sure we're dealing with an archive
   if (!checkSignature(ErrorMsg))
@@ -477,7 +476,8 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
 
   // Module hasn't been loaded yet, we need to load it
   const char* modptr = base + fileOffset;
-  ArchiveMember* mbr = parseMemberHeader(modptr, base + mapfile->size(),ErrMsg);
+  ArchiveMember* mbr = parseMemberHeader(modptr, mapfile->getBufferEnd(),
+                                         ErrMsg);
   if (!mbr)
     return 0;
 
@@ -516,8 +516,8 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
     // below.
 
     // Get a pointer to the first file
-    const char* At  = ((const char*)base) + firstFileOffset;
-    const char* End = ((const char*)base) + mapfile->size();
+    const char* At  = base + firstFileOffset;
+    const char* End = mapfile->getBufferEnd();
 
     while ( At < End) {
       // Compute the offset to be put in the symbol table
@@ -588,7 +588,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
 bool Archive::isBitcodeArchive() {
   // Make sure the symTab has been loaded. In most cases this should have been
   // done when the archive was constructed, but still,  this is just in case.
-  if (!symTab.size())
+  if (symTab.empty())
     if (!loadSymbolTable(0))
       return false;