about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMartinNowack <martin.nowack@gmail.com>2014-04-15 14:54:52 +0200
committerMartinNowack <martin.nowack@gmail.com>2014-04-15 14:54:52 +0200
commit5e0682ee26e02c710abd284f9f965e7a2c9a9f32 (patch)
tree69bcaf2485b5b0dcecc32002de9335b667f65d0b
parent237899d2fe681e5ea70baef5104c43feba87dea2 (diff)
parent78e06cb737e3e54e6c7035822f39961679e7b367 (diff)
downloadklee-5e0682ee26e02c710abd284f9f965e7a2c9a9f32.tar.gz
Merge pull request #104 from MartinNowack/llvm_34
Merge support for LLVM 3.4
-rw-r--r--lib/Core/StatsTracker.cpp26
-rw-r--r--lib/Module/KModule.cpp13
-rw-r--r--lib/Module/ModuleUtil.cpp4
-rw-r--r--lib/Module/Optimize.cpp2
-rw-r--r--test/lit.cfg19
-rw-r--r--test/lit.site.cfg.in9
-rw-r--r--test/regression/2007-08-08-free-zero.c4
-rw-r--r--tools/klee/main.cpp176
8 files changed, 135 insertions, 118 deletions
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index 8161a52c..4709a5bc 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -49,12 +49,11 @@
 #include "llvm/Support/raw_os_ostream.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Path.h"
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
 #include "llvm/Support/FileSystem.h"
-#endif
 
 #include <iostream>
 #include <fstream>
+#include <unistd.h>
 
 using namespace klee;
 using namespace llvm;
@@ -182,20 +181,15 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename,
     updateMinDistToUncovered(_updateMinDistToUncovered) {
   KModule *km = executor.kmodule;
 
-  sys::Path module(objectFilename);
-#if LLVM_VERSION_CODE < LLVM_VERSION(3, 1)
-  if (!sys::Path(objectFilename).isAbsolute()) {
-#else
   if (!sys::path::is_absolute(objectFilename)) {
-#endif
-    sys::Path current = sys::Path::GetCurrentDirectory();
-    current.appendComponent(objectFilename);
-#if LLVM_VERSION_CODE < LLVM_VERSION(3, 1)
-    if (current.exists())
-#else
-    if (sys::fs::exists(current.c_str()))
-#endif
-      objectFilename = current.c_str();
+    SmallString<128> current(objectFilename);
+    if(sys::fs::make_absolute(current)) {
+      bool exists = false;
+      error_code ec = sys::fs::exists(current.str(), exists);
+      if (ec == errc::success && exists) {
+        objectFilename = current.c_str();
+      }
+    }
   }
 
   if (OutputIStats)
@@ -446,7 +440,7 @@ void StatsTracker::writeIStats() {
 
   of << "version: 1\n";
   of << "creator: klee\n";
-  of << "pid: " << sys::Process::GetCurrentUserId() << "\n";
+  of << "pid: " << getpid() << "\n";
   of << "cmd: " << m->getModuleIdentifier() << "\n\n";
   of << "\n";
   
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 2ecb14b8..e06e722a 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -375,13 +375,16 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
   // FIXME: Find a way that we can test programs without requiring
   // this to be linked in, it makes low level debugging much more
   // annoying.
-  llvm::sys::Path path(opts.LibraryDir);
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
-  path.appendComponent("kleeRuntimeIntrinsic.bc");
+
+  SmallString<128> LibPath(opts.LibraryDir);
+  llvm::sys::path::append(LibPath,
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3,3)
+      "kleeRuntimeIntrinsic.bc"
 #else
-  path.appendComponent("libkleeRuntimeIntrinsic.bca");
+      "libkleeRuntimeIntrinsic.bca"
 #endif
-  module = linkWithLibrary(module, path.c_str());
+    );
+  module = linkWithLibrary(module, LibPath.str());
 
   // Add internal functions which are not used to check if instructions
   // have been already visited
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index 58096de4..4f65d0e7 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -13,6 +13,10 @@
 #include "../Core/Common.h"
 #include "../Core/SpecialFunctionHandler.h"
 
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 4)
+#include "llvm/IR/LLVMContext.h"
+#endif
+
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/Function.h"
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index 41a106f1..9c200bc8 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -124,7 +124,9 @@ static void AddStandardCompilePasses(PassManager &PM) {
     addPass(PM, createFunctionInliningPass());   // Inline small functions
   addPass(PM, createArgumentPromotionPass());    // Scalarize uninlined fn args
 
+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 4)
   addPass(PM, createSimplifyLibCallsPass());     // Library Call Optimizations
+#endif
   addPass(PM, createInstructionCombiningPass()); // Cleanup for scalarrepl.
   addPass(PM, createJumpThreadingPass());        // Thread jumps.
   addPass(PM, createCFGSimplificationPass());    // Merge & remove BBs
diff --git a/test/lit.cfg b/test/lit.cfg
index 23696138..3d00da53 100644
--- a/test/lit.cfg
+++ b/test/lit.cfg
@@ -3,6 +3,15 @@
 # Configuration file for the 'lit' test runner.
 
 import os
+import sys
+import re
+import platform
+
+try:
+   import lit.util
+   import lit.formats
+except ImportError:
+   pass
 
 # name: The name of this test suite.
 config.name = 'KLEE'
@@ -66,8 +75,14 @@ for name in subs:
 
 # Get KLEE and Kleaver specific parameters passed on llvm-lit cmd line
 # e.g. llvm-lit --param klee_opts=--help
-klee_extra_params = lit.params.get('klee_opts',"")
-kleaver_extra_params = lit.params.get('kleaver_opts',"")
+try:
+  lit.params
+except AttributeError:
+  klee_extra_params = lit_config.params.get('klee_opts',"")
+  kleaver_extra_params = lit_config.params.get('kleaver_opts',"")
+else:
+  klee_extra_params = lit.params.get('klee_opts',"")
+  kleaver_extra_params = lit.params.get('kleaver_opts',"")
 
 if len(klee_extra_params) != 0:
     print("Passing extra KLEE command line args: {0}".format(klee_extra_params))
diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
index 6fc3d49c..14ba94e6 100644
--- a/test/lit.site.cfg.in
+++ b/test/lit.site.cfg.in
@@ -22,4 +22,11 @@ config.have_selinux = True if @HAVE_SELINUX@ == 1 else False
 config.target_triple = "@TARGET_TRIPLE@"
 
 # Let the main config do the real work.
-lit.load_config(config, "@KLEE_SOURCE_DIR@/test/lit.cfg")
+try:
+  lit
+except NameError:
+  # Use lit_config class
+  lit_config.load_config(config, "@KLEE_SOURCE_DIR@/test/lit.cfg")
+else:
+  # Use old lit class
+  lit.load_config(config, "@KLEE_SOURCE_DIR@/test/lit.cfg")
diff --git a/test/regression/2007-08-08-free-zero.c b/test/regression/2007-08-08-free-zero.c
index 964889a1..935b04fd 100644
--- a/test/regression/2007-08-08-free-zero.c
+++ b/test/regression/2007-08-08-free-zero.c
@@ -1,6 +1,8 @@
 // RUN: %llvmgcc %s -emit-llvm -O0 -c -o %t1.bc
 // RUN: %klee %t1.bc
-// RUN: ls klee-last | not grep *.err
+// RUN: ls %T/klee-last | not grep *.err
+
+#include <stdlib.h>
 
 int main() {
   free(0);
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 1fe28270..a2268c83 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
 
 // FIXME: Ugh, this is gross. But otherwise our config.h conflicts with LLVMs.
 #undef PACKAGE_BUGREPORT
@@ -222,7 +223,8 @@ private:
   TreeStreamWriter *m_pathWriter, *m_symPathWriter;
   std::ostream *m_infoFile;
 
-  sys::Path m_outputDirectory;
+  SmallString<128> m_outputDirectory;
+
   unsigned m_testIndex;  // number of tests written so far
   unsigned m_pathsExplored; // number of paths explored so far
 
@@ -261,7 +263,7 @@ public:
   static void getOutFiles(std::string path,
 			  std::vector<std::string> &results);
 
-  static llvm::sys::Path getRunTimeLibraryPath(const char* argv0, void *MainExecAddr);
+  static std::string getRunTimeLibraryPath(const char* argv0, void *MainExecAddr);
 };
 
 KleeHandler::KleeHandler(int argc, char **argv) 
@@ -275,81 +277,66 @@ KleeHandler::KleeHandler(int argc, char **argv)
     m_argc(argc),
     m_argv(argv) {
 
-  if (OutputDir=="") {
-    llvm::sys::Path directory(InputFile);
-    std::stringstream dirname;
-    directory.eraseComponent();
-    
-    if (directory.isEmpty())
-      directory.set(".");
-    
-    for (int i = 0; i< INT_MAX ; i++) {
-      dirname << "klee-out-";
-      dirname << i;
+  // create output directory (OutputDir or "klee-out-<i>")
+  bool dir_given = OutputDir != "";
+  SmallString<128> directory(dir_given ? OutputDir : InputFile);
 
-      m_outputDirectory = llvm::sys::Path(directory); // Copy
-      if (!m_outputDirectory.appendComponent(dirname.str()))
-        klee_error("Failed to append \"%s\" to \"%s\"", dirname.str().c_str(), directory.c_str());
-      
-      bool isDir = true;
-      llvm::error_code e = llvm::sys::fs::exists(m_outputDirectory.str(), isDir);
-      if ( e != llvm::errc::success )
-        klee_error("Failed to check if \"%s\" exists.", m_outputDirectory.str().c_str());
-
-      if (!isDir)
-      {
-        break; // Found an available directory name
-      }
+  error_code ec;
+  if (!dir_given) sys::path::remove_filename(directory);
+  if ((ec = sys::fs::make_absolute(directory)) != errc::success)
+    klee_error("unable to determine absolute path: %s", ec.message().c_str());
 
-      // Warn the user if the klee-out-* exists but is not a directory
-      e = llvm::sys::fs::is_directory(m_outputDirectory.str(), isDir);
-      if ( e == llvm::errc::success && !isDir )
-        klee_warning("A file \"%s\" exists, but it is not a directory",
-                     m_outputDirectory.str().c_str());
+  if (dir_given) {
+    // OutputDir
+    if (mkdir(directory.c_str(), 0775) < 0)
+      klee_error("cannot create \"%s\": %s", directory.c_str(), strerror(errno));
 
-      dirname.str(""); // Clear
-      m_outputDirectory.clear();
-    }    
+    m_outputDirectory = directory;
+  } else {
+    // "klee-out-<i>"
+    int i = 0;
+    for (; i <= INT_MAX; ++i) {
+      SmallString<128> d(directory);
+      llvm::sys::path::append(d, "klee-out-");
+      raw_svector_ostream ds(d); ds << i; ds.flush();
 
-    if (m_outputDirectory.empty())
-      klee_error("Failed to find available output directory in %s", dirname.str().c_str());
+      // create directory and try to link klee-last
+      if (mkdir(d.c_str(), 0775) == 0) {
+        m_outputDirectory = d;
 
-    std::cerr << "KLEE: output directory = \"" << dirname.str() << "\"\n";
+        SmallString<128> klee_last(directory);
+        llvm::sys::path::append(klee_last, "klee-last");
 
-    llvm::sys::Path klee_last(directory);
-    if(!klee_last.appendComponent("klee-last"))
-      klee_error("cannot create path name for klee-last");
+        if (((unlink(klee_last.c_str()) < 0) && (errno != ENOENT)) ||
+            symlink(m_outputDirectory.c_str(), klee_last.c_str()) < 0) {
 
-    if ((unlink(klee_last.c_str()) < 0) && (errno != ENOENT))
-      klee_error("cannot unlink klee-last: %s", strerror(errno));
-    
-    if (symlink(dirname.str().c_str(), klee_last.c_str()) < 0)
-      klee_error("cannot create klee-last symlink: %s", strerror(errno));
+          klee_warning("cannot create klee-last symlink: %s", strerror(errno));
+        }
 
-  } else {
-    if (!m_outputDirectory.set(OutputDir))
-      klee_error("cannot use klee output directory: %s", OutputDir.c_str());
-  }
-  
-  if (!sys::path::is_absolute(m_outputDirectory.c_str())) {
-    sys::Path cwd = sys::Path::GetCurrentDirectory();
-    if(!cwd.appendComponent( m_outputDirectory.c_str()))
-      klee_error("cannot create absolute path name for output directory");
+        break;
+      }
 
-    m_outputDirectory = cwd;
+      // otherwise try again or exit on error
+      if (errno != EEXIST)
+        klee_error("cannot create \"%s\": %s", m_outputDirectory.c_str(), strerror(errno));
+    }
+    if (i == INT_MAX && m_outputDirectory.str().equals(""))
+        klee_error("cannot create output directory: index out of range");
   }
 
-  if (mkdir(m_outputDirectory.c_str(), 0775) < 0)
-    klee_error("cannot create directory \"%s\": %s", m_outputDirectory.c_str(), strerror(errno));
+  klee_message("output directory is \"%s\"", m_outputDirectory.c_str());
 
+  // open warnings.txt
   std::string file_path = getOutputFilename("warnings.txt");
   if ((klee_warning_file = fopen(file_path.c_str(), "w")) == NULL)
     klee_error("cannot open file \"%s\": %s", file_path.c_str(), strerror(errno));
 
+  // open messages.txt
   file_path = getOutputFilename("messages.txt");
   if ((klee_message_file = fopen(file_path.c_str(), "w")) == NULL)
     klee_error("cannot open file \"%s\": %s", file_path.c_str(), strerror(errno));
 
+  // open info
   m_infoFile = openOutputFile("info");
 }
 
@@ -378,11 +365,8 @@ void KleeHandler::setInterpreter(Interpreter *i) {
 }
 
 std::string KleeHandler::getOutputFilename(const std::string &filename) {
-  sys::Path path(m_outputDirectory);
-  if(!path.appendComponent(filename)) {
-    klee_error("cannot create path name for \"%s\"", filename.c_str());
-  }
-
+  SmallString<128> path = m_outputDirectory;
+  sys::path::append(path,filename);
   return path.str();
 }
 
@@ -557,47 +541,54 @@ void KleeHandler::loadPathFile(std::string name,
 
 void KleeHandler::getOutFiles(std::string path,
 			      std::vector<std::string> &results) {
-  llvm::sys::Path p(path);
-  std::set<llvm::sys::Path> contents;
-  std::string error;
-  if (p.getDirectoryContents(contents, &error)) {
-    std::cerr << "ERROR: unable to read output directory: " << path 
-               << ": " << error << "\n";
-    exit(1);
-  }
-  for (std::set<llvm::sys::Path>::iterator it = contents.begin(),
-         ie = contents.end(); it != ie; ++it) {
-    std::string f = it->str();
+  error_code ec;
+  for (llvm::sys::fs::directory_iterator i(path,ec),e; i!=e && !ec; i.increment(ec)){
+    std::string f = (*i).path();
     if (f.substr(f.size()-6,f.size()) == ".ktest") {
-      results.push_back(f);
+          results.push_back(f);
     }
   }
-}
 
+  if (ec) {
+    std::cerr << "ERROR: unable to read output directory: " << path
+               << ": " << ec.message() << "\n";
+    exit(1);
+  }
+}
 
-llvm::sys::Path KleeHandler::getRunTimeLibraryPath(const char* argv0, void* MainExecAddr)
+std::string KleeHandler::getRunTimeLibraryPath(const char* argv0, void* MainExecAddr)
 {
-  llvm::sys::Path toolRoot = llvm::sys::Path::GetMainExecutable(argv0, MainExecAddr);
-  toolRoot.eraseComponent(); // Strip off executable so we have a directory path
+  SmallString<128> toolRoot(
+      #if LLVM_VERSION_CODE >= LLVM_VERSION(3,4)
+      llvm::sys::fs::getMainExecutable(argv0, MainExecAddr)
+      #else
+      llvm::sys::Path::GetMainExecutable(argv0, MainExecAddr).str()
+      #endif
+      );
 
-  llvm::sys::Path libDir;
+  // Strip off executable so we have a directory path
+  llvm::sys::path::remove_filename(toolRoot);
+
+  SmallString<128> libDir;
 
   if ( strcmp(toolRoot.c_str(), KLEE_INSTALL_BIN_DIR ) == 0)
   {
     DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() <<
                     "Using installed KLEE library runtime: ");
-    libDir = llvm::sys::Path( KLEE_INSTALL_LIB_DIR );
+    libDir = KLEE_INSTALL_LIB_DIR ;
   }
   else
   {
     DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() <<
                     "Using build directory KLEE library runtime :");
-    libDir = llvm::sys::Path(KLEE_DIR "/" RUNTIME_CONFIGURATION "/lib");
+    libDir = KLEE_DIR;
+    llvm::sys::path::append(libDir,RUNTIME_CONFIGURATION);
+    llvm::sys::path::append(libDir,"lib");
   }
 
   DEBUG_WITH_TYPE("klee_runtime", llvm::dbgs() <<
                   libDir.c_str() << "\n");
-  return libDir;
+  return libDir.str();
 }
 
 //===----------------------------------------------------------------------===//
@@ -1031,11 +1022,10 @@ static void replaceOrRenameFunction(llvm::Module *module,
     }
   }
 }
-
-static llvm::Module *linkWithUclibc(llvm::Module *mainModule, llvm::sys::Path libDir) {
+static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir) {
   // Ensure that klee-uclibc exists
-  llvm::sys::Path uclibcBCA(libDir);
-  uclibcBCA.appendComponent(KLEE_UCLIBC_BCA_NAME);
+  SmallString<128> uclibcBCA(libDir);
+  llvm::sys::path::append(uclibcBCA, KLEE_UCLIBC_BCA_NAME);
 
   bool uclibcExists=false;
   llvm::sys::fs::exists(uclibcBCA.c_str(), uclibcExists);
@@ -1261,7 +1251,7 @@ int main(int argc, char **argv, char **envp) {
       return r;
   }
 
-  llvm::sys::Path LibraryDir = KleeHandler::getRunTimeLibraryPath(argv[0], 
+  std::string LibraryDir = KleeHandler::getRunTimeLibraryPath(argv[0],
                               reinterpret_cast<void*>(main));
   Interpreter::ModuleOptions Opts(LibraryDir.c_str(),
                                   /*Optimize=*/OptimizeModule, 
@@ -1274,11 +1264,11 @@ int main(int argc, char **argv, char **envp) {
 
   case KleeLibc: {
     // FIXME: Find a reasonable solution for this.
-    llvm::sys::Path Path(Opts.LibraryDir);
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
-    Path.appendComponent("klee-libc.bc");
+    SmallString<128> Path(Opts.LibraryDir);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3,3)
+    llvm::sys::path::append(Path, "klee-libc.bc");
 #else
-    Path.appendComponent("libklee-libc.bca");
+    llvm::sys::path::append(Path, "libklee-libc.bca");
 #endif
     mainModule = klee::linkWithLibrary(mainModule, Path.c_str());
     assert(mainModule && "unable to link with klee-libc");
@@ -1291,8 +1281,8 @@ int main(int argc, char **argv, char **envp) {
   }
 
   if (WithPOSIXRuntime) {
-    llvm::sys::Path Path(Opts.LibraryDir);
-    Path.appendComponent("libkleeRuntimePOSIX.bca");
+    SmallString<128> Path(Opts.LibraryDir);
+    llvm::sys::path::append(Path, "libkleeRuntimePOSIX.bca");
     klee_message("NOTE: Using model: %s", Path.c_str());
     mainModule = klee::linkWithLibrary(mainModule, Path.c_str());
     assert(mainModule && "unable to link with simple model");