bitcodify, remove eh cruft
[oota-llvm.git] / tools / llvm-ar / llvm-ar.cpp
index 1e8bcec463a545dfcfa173f1720f823cf13092fd..7f6afc6bee28afda8c3497dd09d2bfb100041207 100644 (file)
 #include "llvm/Bytecode/Archive.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compressor.h"
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/System/Signals.h"
 #include <iostream>
 #include <algorithm>
 #include <iomanip>
 #include <memory>
-
 using namespace llvm;
 
 // Option for compatibility with ASIX, not used but must allow it to be present.
@@ -281,16 +281,17 @@ recurseDirectories(const sys::Path& path,
     for (std::set<sys::Path>::iterator I = content.begin(), E = content.end();
          I != E; ++I) {
       // Make sure it exists and is a directory
-      sys::FileStatus Status;
-      if (I->getFileStatus(Status)) {
-        if (Status.isDir) {
-          std::set<sys::Path> moreResults;
-          if (recurseDirectories(*I, moreResults, ErrMsg))
-            return true;
-          result.insert(moreResults.begin(), moreResults.end());
-        } else {
+      sys::PathWithStatus PwS(*I);
+      const sys::FileStatus *Status = PwS.getFileStatus(false, ErrMsg);
+      if (!Status)
+        return true;
+      if (Status->isDir) {
+        std::set<sys::Path> moreResults;
+        if (recurseDirectories(*I, moreResults, ErrMsg))
+          return true;
+        result.insert(moreResults.begin(), moreResults.end());
+      } else {
           result.insert(*I);
-        }
       }
     }
   }
@@ -308,11 +309,12 @@ bool buildPaths(bool checkExistence, std::string* ErrMsg) {
     if (checkExistence) {
       if (!aPath.exists())
         throw std::string("File does not exist: ") + Members[i];
-      sys::FileStatus si;
       std::string Err;
-      if (aPath.getFileStatus(si, &Err))
+      sys::PathWithStatus PwS(aPath);
+      const sys::FileStatus *si = PwS.getFileStatus(false, &Err);
+      if (!si)
         throw Err;
-      if (si.isDir) {
+      if (si->isDir) {
         std::set<sys::Path> dirpaths;
         if (recurseDirectories(aPath, dirpaths, ErrMsg))
           return true;
@@ -644,14 +646,15 @@ doReplaceOrInsert(std::string* ErrMsg) {
     }
 
     if (found != remaining.end()) {
-      sys::FileStatus si;
       std::string Err;
-      if (found->getFileStatus(si, &Err))
+      sys::PathWithStatus PwS(*found); 
+      const sys::FileStatus *si = PwS.getFileStatus(false, &Err);
+      if (!si)
         return true;
-      if (si.isDir) {
+      if (si->isDir) {
         if (OnlyUpdate) {
           // Replace the item only if it is newer.
-          if (si.modTime > I->getModTime())
+          if (si->modTime > I->getModTime())
             if (I->replaceWith(*found, ErrMsg))
               return true;
         } else {
@@ -696,6 +699,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
 
 // main - main program for llvm-ar .. see comments in the code
 int main(int argc, char **argv) {
+  llvm_shutdown_obj X;  // Call llvm_shutdown() on exit.
 
   // Have the command line options parsed and handle things
   // like --help and --version.