diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Core/Common.cpp | 72 | ||||
-rw-r--r-- | lib/Core/Executor.cpp | 38 | ||||
-rw-r--r-- | lib/Core/Executor.h | 4 | ||||
-rw-r--r-- | lib/Core/ExecutorUtil.cpp | 3 | ||||
-rw-r--r-- | lib/Core/ExternalDispatcher.cpp | 9 | ||||
-rw-r--r-- | lib/Core/Searcher.cpp | 8 | ||||
-rw-r--r-- | lib/Core/StatsTracker.cpp | 23 | ||||
-rw-r--r-- | lib/Module/Checks.cpp | 1 | ||||
-rw-r--r-- | lib/Module/InstructionInfoTable.cpp | 50 | ||||
-rw-r--r-- | lib/Module/KModule.cpp | 56 | ||||
-rw-r--r-- | lib/Module/ModuleUtil.cpp | 15 | ||||
-rw-r--r-- | lib/Module/Optimize.cpp | 19 | ||||
-rw-r--r-- | lib/Solver/QueryLoggingSolver.cpp | 8 | ||||
-rw-r--r-- | lib/Support/TreeStream.cpp | 5 |
14 files changed, 188 insertions, 123 deletions
diff --git a/lib/Core/Common.cpp b/lib/Core/Common.cpp index 575a1f1b..c58e121a 100644 --- a/lib/Core/Common.cpp +++ b/lib/Core/Common.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "Common.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" #include <stdlib.h> #include <stdio.h> @@ -22,16 +24,72 @@ using namespace klee; FILE* klee::klee_warning_file = NULL; FILE* klee::klee_message_file = NULL; -static void klee_vfmessage(FILE *fp, const char *pfx, const char *msg, +static const char* warningPrefix = "WARNING"; +static const char* warningOncePrefix = "WARNING ONCE"; +static const char* errorPrefix = "ERROR"; +static const char* notePrefix = "NOTE"; + +static bool shouldSetColor(const char* pfx, const char* msg, const char* prefixToSearchFor) +{ + if (pfx && strcmp(pfx, prefixToSearchFor) == 0) + return true; + + if (llvm::StringRef(msg).startswith(prefixToSearchFor)) + return true; + + return false; +} + +static void klee_vfmessage(FILE *fp, const char *pfx, const char *msg, va_list ap) { if (!fp) return; - fprintf(fp, "KLEE: "); - if (pfx) fprintf(fp, "%s: ", pfx); + llvm::raw_fd_ostream fdos(fileno(fp), /*shouldClose=*/false, /*unbuffered=*/ true); + bool modifyConsoleColor = fdos.is_displayed() && (fp == stderr); + + if (modifyConsoleColor) { + + // Warnings + if (shouldSetColor(pfx, msg, warningPrefix)) + fdos.changeColor(llvm::raw_ostream::MAGENTA, + /*bold=*/ false, + /*bg=*/ false); + + // Once warning + if (shouldSetColor(pfx, msg, warningOncePrefix)) + fdos.changeColor(llvm::raw_ostream::MAGENTA, + /*bold=*/ true, + /*bg=*/ false); + + // Errors + if (shouldSetColor(pfx, msg, errorPrefix)) + fdos.changeColor(llvm::raw_ostream::RED, + /*bold=*/ true, + /*bg=*/ false); + + // Notes + if (shouldSetColor(pfx, msg, notePrefix)) + fdos.changeColor(llvm::raw_ostream::WHITE, + /*bold=*/ true, + /*bg=*/ false); + + } + + fdos << "KLEE: "; + if (pfx) fdos << pfx << ": "; + + // FIXME: Can't use fdos here because we need to print + // a variable number of arguments and do substitution vfprintf(fp, msg, ap); - fprintf(fp, "\n"); fflush(fp); + + fdos << "\n"; + + if (modifyConsoleColor) + fdos.resetColor(); + + fdos.flush(); } /* Prints a message/warning. @@ -73,7 +131,7 @@ void klee::klee_message_to_file(const char *msg, ...) { void klee::klee_error(const char *msg, ...) { va_list ap; va_start(ap, msg); - klee_vmessage("ERROR", false, msg, ap); + klee_vmessage(errorPrefix, false, msg, ap); va_end(ap); exit(1); } @@ -81,7 +139,7 @@ void klee::klee_error(const char *msg, ...) { void klee::klee_warning(const char *msg, ...) { va_list ap; va_start(ap, msg); - klee_vmessage("WARNING", false, msg, ap); + klee_vmessage(warningPrefix, false, msg, ap); va_end(ap); } @@ -104,7 +162,7 @@ void klee::klee_warning_once(const void *id, const char *msg, ...) { va_list ap; va_start(ap, msg); - klee_vmessage("WARNING ONCE", false, msg, ap); + klee_vmessage(warningOncePrefix, false, msg, ap); va_end(ap); } } diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index d2978642..314e5b82 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -78,12 +78,17 @@ #endif #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/CallSite.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <cassert> #include <algorithm> #include <iomanip> @@ -139,10 +144,6 @@ namespace { cl::init(false)); cl::opt<bool> - UseAsmAddresses("use-asm-addresses", - cl::init(false)); - - cl::opt<bool> RandomizeFork("randomize-fork", cl::init(false), cl::desc("Randomly swap the true and false states on a fork (default=off)")); @@ -580,32 +581,9 @@ void Executor::initializeGlobals(ExecutionState &state) { } else { LLVM_TYPE_Q Type *ty = i->getType()->getElementType(); uint64_t size = kmodule->targetData->getTypeStoreSize(ty); - MemoryObject *mo = 0; - -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 3) - if (UseAsmAddresses && i->getName()[0]=='\01') { -#else - if (UseAsmAddresses && !i->getName().empty()) { -#endif - char *end; -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 3) - uint64_t address = ::strtoll(i->getName().str().c_str()+1, &end, 0); -#else - uint64_t address = ::strtoll(i->getName().str().c_str(), &end, 0); -#endif - - if (end && *end == '\0') { - klee_message("NOTE: allocated global at asm specified address: %#08llx" - " (%llu bytes)", - (long long) address, (unsigned long long) size); - mo = memory->allocateFixed(address, size, &*i); - mo->isUserSpecified = true; // XXX hack; - } - } - + MemoryObject *mo = memory->allocate(size, false, true, &*i); if (!mo) - mo = memory->allocate(size, false, true, &*i); - assert(mo && "out of memory"); + llvm::report_fatal_error("out of memory"); ObjectState *os = bindObjectInState(state, mo, false); globalObjects.insert(std::make_pair(i, mo)); globalAddresses.insert(std::make_pair(i, mo->getBaseExpr())); diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h index 7d82332c..523b3648 100644 --- a/lib/Core/Executor.h +++ b/lib/Core/Executor.h @@ -20,7 +20,9 @@ #include "klee/Internal/Module/Cell.h" #include "klee/Internal/Module/KInstruction.h" #include "klee/Internal/Module/KModule.h" -#include "llvm/Support/CallSite.h" + +#include "llvm/ADT/Twine.h" + #include <vector> #include <string> #include <map> diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp index f6b3dd5e..56f18e6b 100644 --- a/lib/Core/ExecutorUtil.cpp +++ b/lib/Core/ExecutorUtil.cpp @@ -38,9 +38,6 @@ #endif #endif -#include "llvm/Support/CallSite.h" - - #include <cassert> using namespace klee; diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp index 4c1e2b86..5f9f8dc6 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -32,14 +32,21 @@ #endif #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/GenericValue.h" -#include "llvm/Support/CallSite.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/raw_ostream.h" + #if LLVM_VERSION_CODE < LLVM_VERSION(3, 0) #include "llvm/Target/TargetSelect.h" #else #include "llvm/Support/TargetSelect.h" #endif + +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <setjmp.h> #include <signal.h> diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp index 2610f17e..e33d2a56 100644 --- a/lib/Core/Searcher.cpp +++ b/lib/Core/Searcher.cpp @@ -34,10 +34,14 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #endif -#include "llvm/Support/CallSite.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/CommandLine.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <cassert> #include <fstream> #include <climits> diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index e664d1ae..0e564fe5 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -52,11 +52,18 @@ #include "llvm/Type.h" #endif #include "llvm/Support/CommandLine.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/Process.h" #include "llvm/Support/Path.h" #include "llvm/Support/FileSystem.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#include "llvm/Support/CFG.h" +#else +#include "llvm/IR/CallSite.h" +#include "llvm/IR/CFG.h" +#endif + #include <fstream> #include <unistd.h> @@ -190,8 +197,13 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename, SmallString<128> current(objectFilename); if(sys::fs::make_absolute(current)) { bool exists = false; + +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) error_code ec = sys::fs::exists(current.str(), exists); if (ec == errc::success && exists) { +#else + if (!sys::fs::exists(current.str(), exists)) { +#endif objectFilename = current.c_str(); } } @@ -501,6 +513,15 @@ void StatsTracker::writeIStats() { for (Module::iterator fnIt = m->begin(), fn_ie = m->end(); fnIt != fn_ie; ++fnIt) { if (!fnIt->isDeclaration()) { + // Always try to write the filename before the function name, as otherwise + // KCachegrind can create two entries for the function, one with an + // unnamed file and one without. + const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fnIt); + if (ii.file != sourceFile) { + of << "fl=" << ii.file << "\n"; + sourceFile = ii.file; + } + of << "fn=" << fnIt->getName().str() << "\n"; for (Function::iterator bbIt = fnIt->begin(), bb_ie = fnIt->end(); bbIt != bb_ie; ++bbIt) { diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp index e1076d43..7d9b7284 100644 --- a/lib/Module/Checks.cpp +++ b/lib/Module/Checks.cpp @@ -45,7 +45,6 @@ #include "llvm/Pass.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" -#include "llvm/Support/CallSite.h" using namespace llvm; using namespace klee; diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp index 8d27e426..7e9a9e26 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -21,17 +21,28 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" #endif -#include "llvm/Linker.h" + +# if LLVM_VERSION_CODE < LLVM_VERSION(3,5) #include "llvm/Assembly/AssemblyAnnotationWriter.h" -#include "llvm/Support/FormattedStream.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/InstIterator.h" +#include "llvm/Linker.h" +#else +#include "llvm/IR/AssemblyAnnotationWriter.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/Linker/Linker.h" +#endif + +#include "llvm/Support/FormattedStream.h" #include "llvm/Support/raw_ostream.h" -#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) + +#if LLVM_VERSION_CODE >= LLVM_VERSION(3,5) +#include "llvm/IR/DebugInfo.h" +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2) #include "llvm/DebugInfo.h" #else #include "llvm/Analysis/DebugInfo.h" #endif + #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/ErrorHandling.h" @@ -110,22 +121,31 @@ InstructionInfoTable::InstructionInfoTable(Module *m) for (Module::iterator fnIt = m->begin(), fn_ie = m->end(); fnIt != fn_ie; ++fnIt) { + // We want to ensure that as all instructions have source information, if + // available. Clang sometimes will not write out debug information on the + // initial instructions in a function (correspond to the formal parameters), + // so we first search forward to find the first instruction with debug info, + // if any. + const std::string *initialFile = &dummyString; + unsigned initialLine = 0; + for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; + ++it) { + if (getInstructionDebugInfo(&*it, initialFile, initialLine)) + break; + } + + const std::string *file = initialFile; + unsigned line = initialLine; for (inst_iterator it = inst_begin(fnIt), ie = inst_end(fnIt); it != ie; ++it) { - const std::string *initialFile = &dummyString; - unsigned initialLine = 0; Instruction *instr = &*it; - unsigned assemblyLine = 0; + unsigned assemblyLine = lineTable[instr]; + + // Update our source level debug information. + getInstructionDebugInfo(instr, file, line); - std::map<const Instruction*, unsigned>::const_iterator ltit = - lineTable.find(instr); - if (ltit!=lineTable.end()) - assemblyLine = ltit->second; - getInstructionDebugInfo(instr, initialFile, initialLine); infos.insert(std::make_pair(instr, - InstructionInfo(id++, - *initialFile, - initialLine, + InstructionInfo(id++, *file, line, assemblyLine))); } } diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 57e0c4fe..1334b58c 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -10,6 +10,7 @@ // FIXME: This does not belong here. #include "../Core/Common.h" +#define DEBUG_TYPE "KModule" #include "klee/Internal/Module/KModule.h" #include "Passes.h" @@ -42,8 +43,13 @@ #endif -#include "llvm/PassManager.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) #include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + +#include "llvm/PassManager.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_os_ostream.h" @@ -51,7 +57,6 @@ #include "llvm/Transforms/Scalar.h" #include <llvm/Transforms/Utils/Cloning.h> -#include <llvm/Support/InstIterator.h> #include <sstream> @@ -224,56 +229,11 @@ static void forceImport(Module *m, const char *name, LLVM_TYPE_Q Type *retType, } #endif -/// This function will take try to inline all calls to \p functionName -/// in the module \p module . -/// -/// It is intended that this function be used for inling calls to -/// check functions like <tt>klee_div_zero_check()</tt> -static void inlineChecks(Module *module, const char * functionName) { - std::vector<CallSite> checkCalls; - Function* runtimeCheckCall = module->getFunction(functionName); - if (runtimeCheckCall == 0) - { - KLEE_DEBUG(klee_warning("Failed to inline %s because no calls were made " - "to it in module", functionName)); - return; - } - - for (Value::use_iterator i = runtimeCheckCall->use_begin(), - e = runtimeCheckCall->use_end(); i != e; ++i) - if (isa<InvokeInst>(*i) || isa<CallInst>(*i)) { - CallSite cs(*i); - if (!cs.getCalledFunction()) - continue; - checkCalls.push_back(cs); - } - - unsigned int successCount=0; - unsigned int failCount=0; - InlineFunctionInfo IFI(0,0); - for ( std::vector<CallSite>::iterator ci = checkCalls.begin(), - cie = checkCalls.end(); - ci != cie; ++ci) - { - // Try to inline the function - if (InlineFunction(*ci,IFI)) - ++successCount; - else - { - ++failCount; - klee_warning("Failed to inline function %s", functionName); - } - } - - KLEE_DEBUG(klee_message("Tried to inline calls to %s. %u successes, " - "%u failures", functionName, successCount, - failCount)); -} void KModule::addInternalFunction(const char* functionName){ Function* internalFunction = module->getFunction(functionName); if (!internalFunction) { - KLEE_DEBUG_WITH_TYPE("KModule", klee_warning( + KLEE_DEBUG(klee_warning( "Failed to add internal function %s. Not found.", functionName)); return ; } diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp index be1ea4c1..3811003e 100644 --- a/lib/Module/ModuleUtil.cpp +++ b/lib/Module/ModuleUtil.cpp @@ -41,15 +41,24 @@ #include "llvm/Module.h" #endif +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) #include "llvm/Linker.h" #include "llvm/Assembly/AssemblyAnnotationWriter.h" -#include "llvm/Support/CFG.h" -#include "llvm/Support/CallSite.h" -#include "llvm/Support/InstIterator.h" +#else +#include "llvm/Linker/Linker.h" +#include "llvm/IR/AssemblyAnnotationWriter.h" +#endif + #include "llvm/Support/raw_ostream.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/Path.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <map> #include <set> #include <fstream> diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp index ed1e0e34..ce43cd96 100644 --- a/lib/Module/Optimize.cpp +++ b/lib/Module/Optimize.cpp @@ -19,7 +19,6 @@ #include "llvm/PassManager.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/LoopPass.h" -#include "llvm/Analysis/Verifier.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DynamicLibrary.h" @@ -35,19 +34,18 @@ #endif #endif +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#include "llvm/IR/Verifier.h" +#else +#include "llvm/Analysis/Verifier.h" +#endif + #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" -#include "llvm/Support/PassNameParser.h" #include "llvm/Support/PluginLoader.h" using namespace llvm; -#if 0 -// Pass Name Options as generated by the PassNameParser -static cl::list<const PassInfo*, bool, PassNameParser> - OptimizationList(cl::desc("Optimizations available:")); -#endif - // Don't verify at the end static cl::opt<bool> DontVerify("disable-verify", cl::ReallyHidden); @@ -177,9 +175,12 @@ void Optimize(Module* M) { #if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1) // Add an appropriate TargetData instance for this module... addPass(Passes, new TargetData(M)); -#else +#elif LLVM_VERSION_CODE < LLVM_VERSION(3, 5) // Add an appropriate DataLayout instance for this module... addPass(Passes, new DataLayout(M)); +#else + // Add an appropriate DataLayout instance for this module... + addPass(Passes, new DataLayoutPass(M)); #endif // DWD - Run the opt standard pass list as well. diff --git a/lib/Solver/QueryLoggingSolver.cpp b/lib/Solver/QueryLoggingSolver.cpp index d5598d1d..5484a319 100644 --- a/lib/Solver/QueryLoggingSolver.cpp +++ b/lib/Solver/QueryLoggingSolver.cpp @@ -4,6 +4,10 @@ #include "klee/Internal/System/Time.h" #include "klee/Statistics.h" +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#include "llvm/Support/FileSystem.h" +#endif + // // The KLEE Symbolic Virtual Machine // @@ -19,7 +23,11 @@ QueryLoggingSolver::QueryLoggingSolver(Solver *_solver, const std::string& commentSign, int queryTimeToLog) : solver(_solver), +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + os(path.c_str(), ErrorInfo, llvm::sys::fs::OpenFlags::F_Text), +#else os(path.c_str(), ErrorInfo), +#endif BufferString(""), logBuffer(BufferString), queryCount(0), diff --git a/lib/Support/TreeStream.cpp b/lib/Support/TreeStream.cpp index 74ffe3ba..ef59b2a9 100644 --- a/lib/Support/TreeStream.cpp +++ b/lib/Support/TreeStream.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#define DEBUG_TYPE "TreeStreamWriter" #include "klee/Internal/ADT/TreeStream.h" #include "klee/Internal/Support/Debug.h" @@ -107,8 +108,7 @@ void TreeStreamWriter::readStream(TreeStreamID streamID, std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); assert(is.good()); - KLEE_DEBUG_WITH_TYPE("TreeStreamWriter", - llvm::errs() << "finding chain for: " << streamID << "\n"); + KLEE_DEBUG(llvm::errs() << "finding chain for: " << streamID << "\n"); std::map<unsigned,unsigned> parents; std::vector<unsigned> roots; @@ -202,3 +202,4 @@ void TreeOStream::flush() { assert(writer); writer->flush(); } + |