Skip to content
This repository was archived by the owner on Feb 3, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions include/klee/BitfieldSimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@

#include "klee/Expr.h"
#include "klee/util/ExprHashMap.h"
#include "llvm/ADT/APInt.h"

namespace klee {

class BitfieldSimplifier {
protected:
struct BitsInfo {
uint64_t ignoredBits; ///< Bits that can be ignored because they
///< are not used by higher-level expressions
///< (passed top-down)
uint64_t knownOneBits; ///< Bits known to be one (passed bottom-up)
uint64_t knownZeroBits; ///< Bits known to be zero (passed bottom-up)
llvm::APInt ignoredBits; ///< Bits that can be ignored because they
///< are not used by higher-level expressions
///< (passed top-down)
llvm::APInt knownOneBits; ///< Bits known to be one (passed bottom-up)
llvm::APInt knownZeroBits; ///< Bits known to be zero (passed bottom-up)
};
typedef std::pair<ref<Expr>, BitsInfo> ExprBitsInfo;

Expand All @@ -51,14 +52,14 @@ class BitfieldSimplifier {

ExprHashMap<ExprBitsInfo> m_simplifiedExpressions;

ref<Expr> replaceWithConstant(ref<Expr> e, uint64_t value);
ref<Expr> replaceWithConstant(ref<Expr> e, const llvm::APInt& value);

ExprBitsInfo doSimplifyBits(ref<Expr> e, uint64_t ignoredBits);
ExprBitsInfo doSimplifyBits(ref<Expr> e, const llvm::APInt& ignoredBits);

public:
uint64_t m_cacheHits, m_cacheMisses;

ref<Expr> simplify(ref<Expr> e, uint64_t *knownZeroBits = NULL);
ref<Expr> simplify(ref<Expr> e, llvm::APInt *knownZeroBits = NULL);

BitfieldSimplifier() {
m_cacheHits = 0;
Expand Down
4 changes: 4 additions & 0 deletions include/klee/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <stdio.h>
#include <unordered_set>

#include "llvm/ADT/APInt.h"

// XXX ugh
namespace klee {
class Solver;
Expand Down Expand Up @@ -75,6 +77,8 @@ struct hexval {
}
hexval(void *_value, int _width = 0) : value((uint64_t) _value), width(_width) {
}
hexval(const llvm::APInt& _value) : value(_value.getLimitedValue()), width(_value.getBitWidth()) {
}
};

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &out, const hexval &h) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Core/AddressSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ bool AddressSpace::resolveOneFast(BitfieldSimplifier &simplifier, ref<Expr> addr
}

ref<Expr> offset = add->getRight();
uint64_t knownZeroBits;
llvm::APInt knownZeroBits;
simplifier.simplify(offset, &knownZeroBits);

uint64_t inBoundsSize;
// Only handle 8-bits sized objects for now.
// TODO: make it work for arbitrary consecutive numbers of 1s.
if ((knownZeroBits & ~(uint64_t) 0xff) == ~(uint64_t) 0xff) {
if ((knownZeroBits & ~llvm::APInt(64, 0xff)) == ~llvm::APInt(64, 0xff)) {
inBoundsSize = 1 << 8;
} else {
return false;
Expand Down
Loading