Skip to content

Commit 6352566

Browse files
fabianbs96mxHuberfabianbssritejakv
authored
Misc Changes (#773)
* replaced llvm-14 with llvm-15 in relevant files * some changes * more efficient call-graph * String-nbased vtable getter + CG-test with dbg info * minor in CG * annotation fix + test fix * removed bitcasts and fixed tests * Fix Annotation.cpp + TaintConfigTest * Quick-fix LLVMTypeHierarchyTest * fix one IIA test * Fix StringtestCpp for generalized LCA * first half of tests fixed * fixed first half of tests * fixed all but one test in IDEInstInteractionAnalysisTest * fixed all but two tests * Fix IIAFlowFact equality * Re-add getVFTableGlobal * fixed some newly failed tests * trade soundness for precision in LLVMAliasSet * ci.yml update * Revert "fixed some newly failed tests" * pre-commit hook * Two Tests + xtaint09 test fix for pipeline * Basic Opaque Pointer Impl, bugged * switching to DebugInfoFinder * re-add the quick-fix for LLVMTypeHierarchy * OpaquePtr type mapping, missing subroutines * Introducing a pass to save ptr types * Revert "Introducing a pass to save ptr types" This reverts commit 2a91b6d. * moving phasar to DIBasedTypeHierarchy * full switch to DIBasedTypeHierarchy + Test fixes * fixed PathTracingTest * dtaresolver deprecated and test fixes * Fixed OTFTest * trimmed trailing whitespace * minor fixes * readded TypeToDIType map for RTAResolver * pre-commit clang-format fix * pre-commit clang-format llvmbasedicfg.cpp * moved RTAResolver to DITypes * implemented review suggestions * Log error if trying to instantiate DTAResolver + minor * Add breaking changes * Also compare gep type in IIA EqualGEPDescriptor * Expose getDILocation() * expose getSrcCodeFromIR for DebugLocation + minor * Remove some unused includes * Make TaintConfigData compatible with C++20 * Compatibility with opaque pointers * Allow setting the LLVM version from higher-level projects * Getting rid of UB in CHAResolver * Start adding more sophisticated type extraction (WIP) * Handle function calls in getVarTypeFromIR * better fallback handling for getDebugLocation, etc * Better IntraMonoSolver dump * minor * improve intra mono dump * minor * expose getNonPureVirtualVFTEntry as namespace-scope function + fix build with LLVM 14 * Fix RTA resolver * Add missing include * Fix solveIFDSProblem + cherry-pick fix of DIBasedTypeHierarchy::buildTypeGraph * dump functions from debugger * Remove unused-variable warning in release mode for CallGraph.h * minor fix in CHA and RTA resolvers * Some cleanup * Add ome additional robustness to LLVMIRToSrc * Fix AllBottom::compose + make FilteredLLVMAliasSet a bit more robust * Make getAllExitPoints more flexible + minor * Handle atexit() in GlobalCtorsDtorsModel (not only __cxa_atexit()) * minor fix in FilteredLLVMAliasSet::isInReachableAllocationSites * pre-commit * pre-commit * Fix name * Fix new CastInfo for EdgeFunction * Make LLVMProjectIRDB movable and add static function load() that returns an ErrorOr * Add function to find the va-list alloca to reduce code duplication * Remove TODO in ProjectIRDB * Apply review comments * minor --------- Co-authored-by: mxHuber <huber.maximilian.leo@gmail.com> Co-authored-by: Fabian Schiebel <fabianbs@mail.uni-paderborn.de> Co-authored-by: Sriteja Kummita <sriteja.ku@gmail.com>
1 parent e3908bd commit 6352566

33 files changed

+554
-362
lines changed

include/phasar/DataFlow/IfdsIde/EdgeFunction.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,7 @@ template <typename L> struct DenseMapInfo<psr::EdgeFunction<L>> {
827827

828828
// LLVM is currently overhauling its casting system. Use the new variant once
829829
// possible!
830-
// Note: The new variant (With CastInfo) is not tested yet!
831-
#if LLVM_MAJOR < 15
830+
#if LLVM_VERSION_MAJOR < 15
832831

833832
template <typename To, typename L>
834833
struct isa_impl_cl<To, const psr::EdgeFunction<L>> {
@@ -876,7 +875,7 @@ cast_or_null(const psr::EdgeFunction<L> &EF) noexcept { // NOLINT
876875
template <typename To, typename L>
877876
struct CastIsPossible<To, psr::EdgeFunction<L>> {
878877
static inline bool isPossible(const psr::EdgeFunction<L> &EF) noexcept {
879-
return EF->template isa<To>();
878+
return EF.template isa<To>();
880879
}
881880
};
882881

include/phasar/DataFlow/IfdsIde/EdgeFunctionUtils.h

Lines changed: 117 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,67 @@ template <typename L> struct EdgeIdentity final {
4040
const EdgeFunction<l_t> &OtherFunction);
4141
};
4242

43+
template <typename L> struct ConstantEdgeFunction {
44+
using l_t = L;
45+
using JLattice = JoinLatticeTraits<L>;
46+
using value_type = typename NonTopBotValue<l_t>::type;
47+
48+
[[nodiscard]] l_t computeTarget(ByConstRef<l_t> /*Source*/) const
49+
noexcept(std::is_nothrow_constructible_v<l_t, const value_type &>) {
50+
static_assert(IsEdgeFunction<ConstantEdgeFunction>);
51+
return Value;
52+
}
53+
54+
template <typename ConcreteEF, typename = std::enable_if_t<std::is_base_of_v<
55+
ConstantEdgeFunction, ConcreteEF>>>
56+
[[nodiscard]] static EdgeFunction<l_t>
57+
compose(EdgeFunctionRef<ConcreteEF> This,
58+
const EdgeFunction<l_t> &SecondFunction);
59+
60+
template <typename ConcreteEF, typename = std::enable_if_t<std::is_base_of_v<
61+
ConstantEdgeFunction, ConcreteEF>>>
62+
[[nodiscard]] static EdgeFunction<l_t>
63+
join(EdgeFunctionRef<ConcreteEF> This,
64+
const EdgeFunction<l_t> &OtherFunction);
65+
66+
[[nodiscard]] constexpr bool isConstant() const noexcept { return true; }
67+
68+
// -- constant data member
69+
70+
value_type Value{};
71+
};
72+
73+
template <typename L, typename = std::enable_if_t<
74+
CanEfficientlyPassByValue<ConstantEdgeFunction<L>>>>
75+
[[nodiscard]] bool operator==(ConstantEdgeFunction<L> LHS,
76+
ConstantEdgeFunction<L> RHS) noexcept {
77+
return LHS.Value == RHS.Value;
78+
}
79+
80+
template <typename L, typename = std::enable_if_t<
81+
!CanEfficientlyPassByValue<ConstantEdgeFunction<L>>>>
82+
[[nodiscard]] bool operator==(const ConstantEdgeFunction<L> &LHS,
83+
const ConstantEdgeFunction<L> &RHS) noexcept {
84+
return LHS.Value == RHS.Value;
85+
}
86+
87+
template <typename L>
88+
[[nodiscard]] llvm::raw_ostream &
89+
operator<<(llvm::raw_ostream &OS, ByConstRef<ConstantEdgeFunction<L>> Id) {
90+
OS << "ConstantEF";
91+
if constexpr (is_llvm_printable_v<
92+
typename ConstantEdgeFunction<L>::value_type>) {
93+
OS << '[' << Id.Value << ']';
94+
}
95+
return OS;
96+
}
97+
4398
template <typename L> struct AllBottom final {
4499
using l_t = L;
45100
using JLattice = JoinLatticeTraits<L>;
46101

47102
[[no_unique_address]] std::conditional_t<HasJoinLatticeTraits<l_t>, EmptyType,
48-
l_t>
49-
BottomValue;
103+
l_t> BottomValue;
50104

51105
[[nodiscard]] l_t computeTarget(ByConstRef<l_t> /*Source*/) const noexcept {
52106
static_assert(std::is_trivially_copyable_v<AllBottom>);
@@ -61,7 +115,25 @@ template <typename L> struct AllBottom final {
61115
[[nodiscard]] static EdgeFunction<l_t>
62116
compose(EdgeFunctionRef<AllBottom> This,
63117
const EdgeFunction<l_t> &SecondFunction) {
64-
return SecondFunction.isConstant() ? SecondFunction : This;
118+
if (SecondFunction.isConstant()) {
119+
return SecondFunction;
120+
}
121+
122+
if constexpr (HasJoinLatticeTraits<L>) {
123+
auto ConstVal = SecondFunction.computeTarget(JLattice::bottom());
124+
if (ConstVal == JLattice::bottom()) {
125+
return This;
126+
}
127+
128+
return ConstantEdgeFunction<L>{
129+
NonTopBotValue<L>::unwrap(std::move(ConstVal))};
130+
} else {
131+
// Note: This used to be the default behavior, but it appears to be too
132+
// restrictive
133+
return This;
134+
}
135+
136+
// return SecondFunction.isConstant() ? SecondFunction : This;
65137
}
66138

67139
[[nodiscard]] static EdgeFunction<l_t>
@@ -85,8 +157,7 @@ template <typename L> struct AllTop final {
85157
using JLattice = JoinLatticeTraits<L>;
86158

87159
[[no_unique_address]] std::conditional_t<HasJoinLatticeTraits<l_t>, EmptyType,
88-
l_t>
89-
TopValue;
160+
l_t> TopValue;
90161

91162
[[nodiscard]] l_t computeTarget(ByConstRef<l_t> /*Source*/) const noexcept {
92163
static_assert(std::is_trivially_copyable_v<AllTop>);
@@ -149,97 +220,6 @@ defaultComposeOrNull(const EdgeFunction<L> &This,
149220
return nullptr;
150221
}
151222

152-
template <typename L> struct ConstantEdgeFunction {
153-
using l_t = L;
154-
using JLattice = JoinLatticeTraits<L>;
155-
using value_type = typename NonTopBotValue<l_t>::type;
156-
157-
[[nodiscard]] l_t computeTarget(ByConstRef<l_t> /*Source*/) const
158-
noexcept(std::is_nothrow_constructible_v<l_t, const value_type &>) {
159-
static_assert(IsEdgeFunction<ConstantEdgeFunction>);
160-
return Value;
161-
}
162-
163-
template <typename ConcreteEF, typename = std::enable_if_t<std::is_base_of_v<
164-
ConstantEdgeFunction, ConcreteEF>>>
165-
[[nodiscard]] static EdgeFunction<l_t>
166-
compose(EdgeFunctionRef<ConcreteEF> This,
167-
const EdgeFunction<l_t> &SecondFunction) {
168-
if (auto Default = defaultComposeOrNull(This, SecondFunction)) {
169-
return Default;
170-
}
171-
172-
auto ConstVal = SecondFunction.computeTarget(This->Value);
173-
if constexpr (!EdgeFunctionBase::IsSOOCandidate<ConstantEdgeFunction>) {
174-
if (ConstVal == This->Value) {
175-
return This;
176-
}
177-
}
178-
179-
if constexpr (AreEqualityComparable<decltype(JLattice::bottom()), l_t>) {
180-
if (JLattice::bottom() == ConstVal) {
181-
return AllBottom<l_t>{};
182-
}
183-
} else {
184-
if (l_t(JLattice::bottom()) == ConstVal) {
185-
return AllBottom<l_t>{};
186-
}
187-
}
188-
189-
if constexpr (AreEqualityComparable<decltype(JLattice::top()), l_t>) {
190-
if (JLattice::top() == ConstVal) {
191-
/// TODO: Can this ever happen?
192-
return AllTop<l_t>{};
193-
}
194-
} else {
195-
if (l_t(JLattice::top()) == ConstVal) {
196-
/// TODO: Can this ever happen?
197-
return AllTop<l_t>{};
198-
}
199-
}
200-
201-
return ConstantEdgeFunction{
202-
NonTopBotValue<l_t>::unwrap(std::move(ConstVal))};
203-
}
204-
205-
template <typename ConcreteEF, typename = std::enable_if_t<std::is_base_of_v<
206-
ConstantEdgeFunction, ConcreteEF>>>
207-
[[nodiscard]] static EdgeFunction<l_t>
208-
join(EdgeFunctionRef<ConcreteEF> This,
209-
const EdgeFunction<l_t> &OtherFunction);
210-
211-
[[nodiscard]] constexpr bool isConstant() const noexcept { return true; }
212-
213-
// -- constant data member
214-
215-
value_type Value{};
216-
};
217-
218-
template <typename L, typename = std::enable_if_t<
219-
CanEfficientlyPassByValue<ConstantEdgeFunction<L>>>>
220-
[[nodiscard]] bool operator==(ConstantEdgeFunction<L> LHS,
221-
ConstantEdgeFunction<L> RHS) noexcept {
222-
return LHS.Value == RHS.Value;
223-
}
224-
225-
template <typename L, typename = std::enable_if_t<
226-
!CanEfficientlyPassByValue<ConstantEdgeFunction<L>>>>
227-
[[nodiscard]] bool operator==(const ConstantEdgeFunction<L> &LHS,
228-
const ConstantEdgeFunction<L> &RHS) noexcept {
229-
return LHS.Value == RHS.Value;
230-
}
231-
232-
template <typename L>
233-
[[nodiscard]] llvm::raw_ostream &
234-
operator<<(llvm::raw_ostream &OS, ByConstRef<ConstantEdgeFunction<L>> Id) {
235-
OS << "ConstantEF";
236-
if constexpr (is_llvm_printable_v<
237-
typename ConstantEdgeFunction<L>::value_type>) {
238-
OS << '[' << Id.Value << ']';
239-
}
240-
return OS;
241-
}
242-
243223
template <typename L> struct EdgeFunctionComposer {
244224
using l_t = L;
245225

@@ -461,6 +441,47 @@ EdgeFunction<L> EdgeIdentity<L>::join(EdgeFunctionRef<EdgeIdentity> This,
461441
return OtherFunction.joinWith(This);
462442
}
463443

444+
template <typename L>
445+
template <typename ConcreteEF, typename>
446+
EdgeFunction<L>
447+
ConstantEdgeFunction<L>::compose(EdgeFunctionRef<ConcreteEF> This,
448+
const EdgeFunction<L> &SecondFunction) {
449+
if (auto Default = defaultComposeOrNull(This, SecondFunction)) {
450+
return Default;
451+
}
452+
453+
auto ConstVal = SecondFunction.computeTarget(This->Value);
454+
if constexpr (!EdgeFunctionBase::IsSOOCandidate<ConstantEdgeFunction>) {
455+
if (ConstVal == This->Value) {
456+
return This;
457+
}
458+
}
459+
460+
if constexpr (AreEqualityComparable<decltype(JLattice::bottom()), L>) {
461+
if (JLattice::bottom() == ConstVal) {
462+
return AllBottom<L>{};
463+
}
464+
} else {
465+
if (L(JLattice::bottom()) == ConstVal) {
466+
return AllBottom<L>{};
467+
}
468+
}
469+
470+
if constexpr (AreEqualityComparable<decltype(JLattice::top()), L>) {
471+
if (JLattice::top() == ConstVal) {
472+
/// TODO: Can this ever happen?
473+
return AllTop<L>{};
474+
}
475+
} else {
476+
if (L(JLattice::top()) == ConstVal) {
477+
/// TODO: Can this ever happen?
478+
return AllTop<L>{};
479+
}
480+
}
481+
482+
return ConstantEdgeFunction{NonTopBotValue<L>::unwrap(std::move(ConstVal))};
483+
}
484+
464485
template <typename L>
465486
template <typename ConcreteEF, typename>
466487
EdgeFunction<L>

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
#include "phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h"
2727
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
2828
#include "phasar/PhasarLLVM/Utils/LLVMBasedContainerConfig.h"
29-
#include "phasar/Utils/MaybeUniquePtr.h"
3029
#include "phasar/Utils/Soundness.h"
3130

3231
#include "llvm/ADT/ArrayRef.h"
3332
#include "llvm/ADT/SmallVector.h"
3433
#include "llvm/IR/Function.h"
35-
#include "llvm/IR/Instruction.h"
3634
#include "llvm/IR/Value.h"
3735
#include "llvm/Support/raw_ostream.h"
3836

include/phasar/PhasarLLVM/ControlFlow/LLVMVFTableProvider.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "phasar/PhasarLLVM/TypeHierarchy/LLVMVFTable.h"
1414

15+
#include "llvm/ADT/StringMap.h"
16+
1517
#include <unordered_map>
1618

1719
namespace llvm {
@@ -38,7 +40,14 @@ class LLVMVFTableProvider {
3840
[[nodiscard]] const LLVMVFTable *
3941
getVFTableOrNull(const llvm::DIType *Type) const;
4042

43+
[[nodiscard]] const llvm::GlobalVariable *
44+
getVFTableGlobal(const llvm::DIType *Type) const;
45+
46+
[[nodiscard]] const llvm::GlobalVariable *
47+
getVFTableGlobal(llvm::StringRef ClearTypeName) const;
48+
4149
private:
50+
llvm::StringMap<const llvm::GlobalVariable *> ClearNameTVMap;
4251
std::unordered_map<const llvm::DIType *, LLVMVFTable> TypeVFTMap;
4352
};
4453
} // namespace psr

include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class Resolver {
113113

114114
[[nodiscard]] virtual std::string str() const = 0;
115115

116+
/// Whether the ICFG needs to reconsider all dynamic call-sites once there
117+
/// have been changes through handlePossibleTargets().
118+
///
119+
/// Make false for performance (may be less sound then)
116120
[[nodiscard]] virtual bool mutatesHelperAnalysisInformation() const noexcept {
117121
// Conservatively returns true. Override if possible
118122
return true;

include/phasar/PhasarLLVM/ControlFlow/SparseLLVMBasedICFG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct SVFGCache;
2424
/// Conforms to the ICFGBase CRTP interface.
2525
///
2626
/// Use this in the IDESolver or IFDSSolver to profit from the SparseIFDS or
27-
/// SparseIDE optimization after Karakays et al. "Symbol-Specific Sparsification
27+
/// SparseIDE optimization after Karakaya et al. "Symbol-Specific Sparsification
2828
/// of Interprocedural Distributive Environment Problems"
2929
/// <https://doi.org/10.48550/arXiv.2401.14813>
3030
class SparseLLVMBasedICFG

include/phasar/PhasarLLVM/ControlFlow/SparseLLVMBasedICFGView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct CFGTraits<SparseLLVMBasedICFGView> : CFGTraits<LLVMBasedCFG> {};
3434
/// It still owns the sparse value-flow graphs.
3535
///
3636
/// Use this in the IDESolver or IFDSSolver to profit from the SparseIFDS or
37-
/// SparseIDE optimization after Karakays et al. "Symbol-Specific Sparsification
37+
/// SparseIDE optimization after Karakaya et al. "Symbol-Specific Sparsification
3838
/// of Interprocedural Distributive Environment Problems"
3939
/// <https://doi.org/10.48550/arXiv.2401.14813>
4040
class SparseLLVMBasedICFGView

0 commit comments

Comments
 (0)