Skip to content

Commit cd302d8

Browse files
authored
Misc Fixes (#698)
* Fix InitialSeeds Join values correctly when reaching a seed location from a different path * Fix MaybeUniquePtr ---------
1 parent 7aae84d commit cd302d8

File tree

8 files changed

+57
-24
lines changed

8 files changed

+57
-24
lines changed

include/phasar/DataFlow/IfdsIde/Solver/IDESolver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,10 @@ class IDESolver
725725
<< ", value: " << LToString(Value));
726726
// initialize the initial seeds with the top element as we have no
727727
// information at the beginning of the value computation problem
728-
setVal(StartPoint, Fact, Value);
728+
l_t OldVal = val(StartPoint, Fact);
729+
auto NewVal = IDEProblem.join(Value, std::move(OldVal));
730+
setVal(StartPoint, Fact, std::move(NewVal));
731+
729732
std::pair<n_t, d_t> SuperGraphNode(StartPoint, Fact);
730733
valuePropagationTask(std::move(SuperGraphNode));
731734
}

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
9696
const nlohmann::json &SerializedCG,
9797
LLVMTypeHierarchy *TH = nullptr);
9898

99+
// Deleter of LLVMTypeHierarchy may be unknown here...
99100
~LLVMBasedICFG();
100101

101102
LLVMBasedICFG(const LLVMBasedICFG &) = delete;

include/phasar/PhasarLLVM/DB/LLVMProjectIRDB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class LLVMProjectIRDB : public ProjectIRDBBase<LLVMProjectIRDB> {
109109
[[nodiscard]] m_t getModuleImpl() const noexcept { return Mod.get(); }
110110
[[nodiscard]] bool debugInfoAvailableImpl() const;
111111
[[nodiscard]] FunctionRange getAllFunctionsImpl() const {
112-
return llvm::map_range(Mod->functions(),
112+
return llvm::map_range(ProjectIRDBBase::getModule()->functions(),
113113
Ref2PointerConverter<llvm::Function>{});
114114
}
115115
[[nodiscard]] f_t getFunctionImpl(llvm::StringRef FunctionName) const {

include/phasar/Utils/DFAMinimizer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ template <typename GraphTy>
110110
}
111111
}
112112

113-
size_t Idx = 0;
114-
115113
llvm::IntEqClasses Equiv(traits_t::size(G));
116114

117115
auto isEquivalent = [&Equiv](edge_t LHS, edge_t RHS) {

include/phasar/Utils/MaybeUniquePtr.h

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define PHASAR_UTILS_MAYBEUNIQUEPTR_H_
1212

1313
#include "llvm/ADT/PointerIntPair.h"
14+
#include "llvm/Support/PointerLikeTypeTraits.h"
1415

1516
#include <memory>
1617
#include <type_traits>
@@ -39,8 +40,12 @@ template <typename T, bool RequireAlignment> class MaybeUniquePtrBase {
3940
};
4041

4142
template <typename T> class MaybeUniquePtrBase<T, true> {
43+
struct PointerTraits : llvm::PointerLikeTypeTraits<T *> {
44+
static constexpr int NumLowBitsAvailable = 1;
45+
};
46+
4247
protected:
43-
llvm::PointerIntPair<T *, 1, bool> Data{};
48+
llvm::PointerIntPair<T *, 1, bool, PointerTraits> Data{};
4449

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

6368
constexpr MaybeUniquePtr(T *Pointer, bool Owns = false) noexcept
64-
: detail::MaybeUniquePtrBase<T, RequireAlignment>(Pointer, Owns) {}
69+
: detail::MaybeUniquePtrBase<T, RequireAlignment>(Pointer,
70+
Owns && Pointer) {}
6571

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

69-
template <typename TT>
75+
template <typename TT,
76+
typename = std::enable_if_t<!std::is_same_v<T, TT> &&
77+
std::is_convertible_v<TT *, T *>>>
7078
constexpr MaybeUniquePtr(std::unique_ptr<TT> &&Owner) noexcept
7179
: MaybeUniquePtr(Owner.release(), true) {}
7280

@@ -92,16 +100,20 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
92100
if (owns()) {
93101
delete Data.getPointer();
94102
}
95-
Data = {Owner.release(), true};
103+
auto *Ptr = Owner.release();
104+
Data = {Ptr, Ptr != nullptr};
96105
return *this;
97106
}
98107

99-
template <typename TT>
108+
template <typename TT,
109+
typename = std::enable_if_t<!std::is_same_v<T, TT> &&
110+
std::is_convertible_v<TT *, T *>>>
100111
constexpr MaybeUniquePtr &operator=(std::unique_ptr<TT> &&Owner) noexcept {
101112
if (owns()) {
102113
delete Data.getPointer();
103114
}
104-
Data = {Owner.release(), true};
115+
auto *Ptr = Owner.release();
116+
Data = {Ptr, Ptr != nullptr};
105117
return *this;
106118
}
107119

@@ -118,24 +130,16 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
118130
}
119131
}
120132

121-
[[nodiscard]] constexpr T *get() noexcept { return Data.getPointer(); }
122-
[[nodiscard]] constexpr const T *get() const noexcept {
123-
return Data.getPointer();
124-
}
133+
[[nodiscard]] constexpr T *get() const noexcept { return Data.getPointer(); }
125134

126-
[[nodiscard]] constexpr T *operator->() noexcept { return get(); }
127-
[[nodiscard]] constexpr const T *operator->() const noexcept { return get(); }
135+
[[nodiscard]] constexpr T *operator->() const noexcept { return get(); }
128136

129-
[[nodiscard]] constexpr T &operator*() noexcept {
130-
assert(get() != nullptr);
131-
return *get();
132-
}
133-
[[nodiscard]] constexpr const T &operator*() const noexcept {
137+
[[nodiscard]] constexpr T &operator*() const noexcept {
134138
assert(get() != nullptr);
135139
return *get();
136140
}
137141

138-
T *release() noexcept {
142+
constexpr T *release() noexcept {
139143
Data.setInt(false);
140144
return Data.getPointer();
141145
}
@@ -147,8 +151,19 @@ class MaybeUniquePtr : detail::MaybeUniquePtrBase<T, RequireAlignment> {
147151
Data = {};
148152
}
149153

154+
template <typename TT>
155+
constexpr void reset(MaybeUniquePtr<TT> &&Other) noexcept {
156+
*this = std::move(Other);
157+
}
158+
159+
template <typename TT>
160+
constexpr void reset(std::unique_ptr<TT> &&Other) noexcept {
161+
*this = std::move(Other);
162+
}
163+
150164
[[nodiscard]] constexpr bool owns() const noexcept {
151-
return Data.getInt() && Data.getPointer();
165+
assert(Data.getPointer() || !Data.getInt());
166+
return Data.getInt();
152167
}
153168

154169
constexpr friend bool operator==(const MaybeUniquePtr &LHS,

lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ LLVMTaintConfig::LLVMTaintConfig(const psr::LLVMProjectIRDB &Code,
130130
std::unordered_map<const llvm::Type *, const std::string> StructConfigMap;
131131

132132
// read all struct types from config
133-
size_t Counter = 0;
134133
for (const auto &VarDesc : Config.Variables) {
135134
llvm::DebugInfoFinder DIF;
136135
const auto *M = Code.getModule();

unittests/Utils/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(UtilsSources
2+
CompilationTests.cpp
23
BitVectorSetTest.cpp
34
EquivalenceClassMapTest.cpp
45
IOTest.cpp
@@ -16,3 +17,5 @@ endif()
1617
foreach(TEST_SRC ${UtilsSources})
1718
add_phasar_unittest(${TEST_SRC})
1819
endforeach(TEST_SRC)
20+
21+
target_compile_options(CompilationTests PRIVATE -Wno-delete-incomplete)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#include "phasar/Utils/MaybeUniquePtr.h"
3+
4+
#include <memory>
5+
6+
struct IncompleteType;
7+
8+
using MUP = psr::MaybeUniquePtr<IncompleteType, true>;
9+
MUP maybeUniquePtrSupportsIncompleteTypes(
10+
std::unique_ptr<IncompleteType> &&UP) {
11+
return std::move(UP);
12+
}
13+
14+
int main() {}

0 commit comments

Comments
 (0)