Skip to content
Merged
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
5 changes: 4 additions & 1 deletion include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,10 @@ class IDESolver
<< ", value: " << LToString(Value));
// initialize the initial seeds with the top element as we have no
// information at the beginning of the value computation problem
setVal(StartPoint, Fact, Value);
l_t OldVal = val(StartPoint, Fact);
auto NewVal = IDEProblem.join(Value, std::move(OldVal));
setVal(StartPoint, Fact, std::move(NewVal));

std::pair<n_t, d_t> SuperGraphNode(StartPoint, Fact);
valuePropagationTask(std::move(SuperGraphNode));
}
Expand Down
1 change: 1 addition & 0 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
const nlohmann::json &SerializedCG,
LLVMTypeHierarchy *TH = nullptr);

// Deleter of LLVMTypeHierarchy may be unknown here...
~LLVMBasedICFG();

LLVMBasedICFG(const LLVMBasedICFG &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarLLVM/DB/LLVMProjectIRDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class LLVMProjectIRDB : public ProjectIRDBBase<LLVMProjectIRDB> {
[[nodiscard]] m_t getModuleImpl() const noexcept { return Mod.get(); }
[[nodiscard]] bool debugInfoAvailableImpl() const;
[[nodiscard]] FunctionRange getAllFunctionsImpl() const {
return llvm::map_range(Mod->functions(),
return llvm::map_range(ProjectIRDBBase::getModule()->functions(),
Ref2PointerConverter<llvm::Function>{});
}
[[nodiscard]] f_t getFunctionImpl(llvm::StringRef FunctionName) const {
Expand Down
2 changes: 0 additions & 2 deletions include/phasar/Utils/DFAMinimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ template <typename GraphTy>
}
}

size_t Idx = 0;

llvm::IntEqClasses Equiv(traits_t::size(G));

auto isEquivalent = [&Equiv](edge_t LHS, edge_t RHS) {
Expand Down
53 changes: 34 additions & 19 deletions include/phasar/Utils/MaybeUniquePtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define PHASAR_UTILS_MAYBEUNIQUEPTR_H_

#include "llvm/ADT/PointerIntPair.h"
#include "llvm/Support/PointerLikeTypeTraits.h"

#include <memory>
#include <type_traits>
Expand Down Expand Up @@ -39,8 +40,12 @@ template <typename T, bool RequireAlignment> class MaybeUniquePtrBase {
};

template <typename T> class MaybeUniquePtrBase<T, true> {
struct PointerTraits : llvm::PointerLikeTypeTraits<T *> {
static constexpr int NumLowBitsAvailable = 1;
};

protected:
llvm::PointerIntPair<T *, 1, bool> Data{};
llvm::PointerIntPair<T *, 1, bool, PointerTraits> Data{};

constexpr MaybeUniquePtrBase(T *Ptr, bool Owns) noexcept : Data{Ptr, Owns} {}
constexpr MaybeUniquePtrBase() noexcept = default;
Expand All @@ -61,12 +66,15 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
constexpr MaybeUniquePtr() noexcept = default;

constexpr MaybeUniquePtr(T *Pointer, bool Owns = false) noexcept
: detail::MaybeUniquePtrBase<T, RequireAlignment>(Pointer, Owns) {}
: detail::MaybeUniquePtrBase<T, RequireAlignment>(Pointer,
Owns && Pointer) {}

constexpr MaybeUniquePtr(std::unique_ptr<T> &&Owner) noexcept
: MaybeUniquePtr(Owner.release(), true) {}

template <typename TT>
template <typename TT,
typename = std::enable_if_t<!std::is_same_v<T, TT> &&
std::is_convertible_v<TT *, T *>>>
constexpr MaybeUniquePtr(std::unique_ptr<TT> &&Owner) noexcept
: MaybeUniquePtr(Owner.release(), true) {}

Expand All @@ -92,16 +100,20 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
if (owns()) {
delete Data.getPointer();
}
Data = {Owner.release(), true};
auto *Ptr = Owner.release();
Data = {Ptr, Ptr != nullptr};
return *this;
}

template <typename TT>
template <typename TT,
typename = std::enable_if_t<!std::is_same_v<T, TT> &&
std::is_convertible_v<TT *, T *>>>
constexpr MaybeUniquePtr &operator=(std::unique_ptr<TT> &&Owner) noexcept {
if (owns()) {
delete Data.getPointer();
}
Data = {Owner.release(), true};
auto *Ptr = Owner.release();
Data = {Ptr, Ptr != nullptr};
return *this;
}

Expand All @@ -118,24 +130,16 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
}
}

[[nodiscard]] constexpr T *get() noexcept { return Data.getPointer(); }
[[nodiscard]] constexpr const T *get() const noexcept {
return Data.getPointer();
}
[[nodiscard]] constexpr T *get() const noexcept { return Data.getPointer(); }

[[nodiscard]] constexpr T *operator->() noexcept { return get(); }
[[nodiscard]] constexpr const T *operator->() const noexcept { return get(); }
[[nodiscard]] constexpr T *operator->() const noexcept { return get(); }

[[nodiscard]] constexpr T &operator*() noexcept {
assert(get() != nullptr);
return *get();
}
[[nodiscard]] constexpr const T &operator*() const noexcept {
[[nodiscard]] constexpr T &operator*() const noexcept {
assert(get() != nullptr);
return *get();
}

T *release() noexcept {
constexpr T *release() noexcept {
Data.setInt(false);
return Data.getPointer();
}
Expand All @@ -147,8 +151,19 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
Data = {};
}

template <typename TT>
constexpr void reset(MaybeUniquePtr<TT> &&Other) noexcept {
*this = std::move(Other);
}

template <typename TT>
constexpr void reset(std::unique_ptr<TT> &&Other) noexcept {
*this = std::move(Other);
}

[[nodiscard]] constexpr bool owns() const noexcept {
return Data.getInt() && Data.getPointer();
assert(Data.getPointer() || !Data.getInt());
return Data.getInt();
}

constexpr friend bool operator==(const MaybeUniquePtr &LHS,
Expand Down
1 change: 0 additions & 1 deletion lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ LLVMTaintConfig::LLVMTaintConfig(const psr::LLVMProjectIRDB &Code,
std::unordered_map<const llvm::Type *, const std::string> StructConfigMap;

// read all struct types from config
size_t Counter = 0;
for (const auto &VarDesc : Config.Variables) {
llvm::DebugInfoFinder DIF;
const auto *M = Code.getModule();
Expand Down
3 changes: 3 additions & 0 deletions unittests/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(UtilsSources
CompilationTests.cpp
BitVectorSetTest.cpp
EquivalenceClassMapTest.cpp
IOTest.cpp
Expand All @@ -16,3 +17,5 @@ endif()
foreach(TEST_SRC ${UtilsSources})
add_phasar_unittest(${TEST_SRC})
endforeach(TEST_SRC)

target_compile_options(CompilationTests PRIVATE -Wno-delete-incomplete)
14 changes: 14 additions & 0 deletions unittests/Utils/CompilationTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#include "phasar/Utils/MaybeUniquePtr.h"

#include <memory>

struct IncompleteType;

using MUP = psr::MaybeUniquePtr<IncompleteType, true>;
MUP maybeUniquePtrSupportsIncompleteTypes(
std::unique_ptr<IncompleteType> &&UP) {
return std::move(UP);
}

int main() {}