Skip to content

Commit 64e8241

Browse files
mxHuberfabianbs96
andauthored
Added default reachable allocation sites functions (#781)
* Base files * Added missing alias elements * tests + normalflow impl * added RAS tests * WIP reworking flow functions * ret and call flow, tests seq fault * fixed seq faults in tests * fixed bugs and unittests * Cleanup + small fixes * pre-commit * Add missing header guards and file headers --------- Co-authored-by: Fabian Schiebel <[email protected]>
1 parent ed7995a commit 64e8241

File tree

9 files changed

+551
-59
lines changed

9 files changed

+551
-59
lines changed

include/phasar/PhasarLLVM/DataFlow/IfdsIde/DefaultAliasAwareIDEProblem.h

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/******************************************************************************
2+
* Copyright (c) 2025 Fabian Schiebel.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, mxHuber and others
8+
*****************************************************************************/
9+
110
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_IDEALIASINFOTABULATIONPROBLEM_H
211
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_IDEALIASINFOTABULATIONPROBLEM_H
312

@@ -38,17 +47,14 @@ class IDEAliasAwareDefaultFlowFunctionsImpl
3847

3948
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunctionImpl(n_t Curr,
4049
n_t /*Succ*/);
41-
[[nodiscard]] FlowFunctionPtrType getCallFlowFunctionImpl(n_t CallInst,
42-
f_t CalleeFun);
4350
[[nodiscard]] FlowFunctionPtrType getRetFlowFunctionImpl(n_t CallSite,
4451
f_t /*CalleeFun*/,
4552
n_t ExitInst,
4653
n_t /*RetSite*/);
47-
[[nodiscard]] FlowFunctionPtrType
48-
getCallToRetFlowFunctionImpl(n_t CallSite, n_t /*RetSite*/,
49-
llvm::ArrayRef<f_t> /*Callees*/);
54+
using IDENoAliasDefaultFlowFunctionsImpl::getCallFlowFunctionImpl;
55+
using IDENoAliasDefaultFlowFunctionsImpl::getCallToRetFlowFunctionImpl;
5056

51-
private:
57+
protected:
5258
LLVMAliasInfoRef AS;
5359
};
5460
} // namespace detail
@@ -58,22 +64,7 @@ class DefaultAliasAwareIDEProblem
5864
: public IDETabulationProblem<AnalysisDomainTy>,
5965
protected detail::IDEAliasAwareDefaultFlowFunctionsImpl {
6066
public:
61-
using ProblemAnalysisDomain = AnalysisDomainTy;
62-
using d_t = typename AnalysisDomainTy::d_t;
63-
using n_t = typename AnalysisDomainTy::n_t;
64-
using f_t = typename AnalysisDomainTy::f_t;
65-
using t_t = typename AnalysisDomainTy::t_t;
66-
using v_t = typename AnalysisDomainTy::v_t;
67-
using l_t = typename AnalysisDomainTy::l_t;
68-
using i_t = typename AnalysisDomainTy::i_t;
69-
using db_t = typename AnalysisDomainTy::db_t;
70-
71-
using ConfigurationTy = HasNoConfigurationType;
72-
73-
using FlowFunctionType = FlowFunction<d_t>;
74-
using FlowFunctionPtrType = typename FlowFunctionType::FlowFunctionPtrType;
75-
76-
using container_type = typename FlowFunctionType::container_type;
67+
using typename IDETabulationProblem<AnalysisDomainTy>::db_t;
7768

7869
/// Constructs an IDETabulationProblem with the usual arguments + alias
7970
/// information.
@@ -86,9 +77,11 @@ class DefaultAliasAwareIDEProblem
8677
std::optional<d_t>
8778
ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
8879
: IDETabulationProblem<AnalysisDomainTy>(IRDB, std::move(EntryPoints),
89-
std::move(ZeroValue)),
80+
ZeroValue),
9081
detail::IDEAliasAwareDefaultFlowFunctionsImpl(AS) {}
9182

83+
using detail::IDEAliasAwareDefaultFlowFunctionsImpl::getAliasInfo;
84+
9285
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
9386
n_t Succ) override {
9487
return getNormalFlowFunctionImpl(Curr, Succ);
@@ -129,6 +122,8 @@ class DefaultAliasAwareIFDSProblem
129122
: IFDSTabulationProblem(IRDB, std::move(EntryPoints), ZeroValue),
130123
detail::IDEAliasAwareDefaultFlowFunctionsImpl(AS) {}
131124

125+
using detail::IDEAliasAwareDefaultFlowFunctionsImpl::getAliasInfo;
126+
132127
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
133128
n_t Succ) override {
134129
return getNormalFlowFunctionImpl(Curr, Succ);

include/phasar/PhasarLLVM/DataFlow/IfdsIde/DefaultNoAliasIDEProblem.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/******************************************************************************
2+
* Copyright (c) 2025 Fabian Schiebel.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, mxHuber and others
8+
*****************************************************************************/
9+
110
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_IDENOALIASINFOTABULATIONPROBLEM_H
211
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_IDENOALIASINFOTABULATIONPROBLEM_H
312

@@ -48,21 +57,6 @@ class DefaultNoAliasIDEProblem
4857
: public IDETabulationProblem<AnalysisDomainTy>,
4958
protected detail::IDENoAliasDefaultFlowFunctionsImpl {
5059
public:
51-
using ProblemAnalysisDomain = AnalysisDomainTy;
52-
using d_t = typename AnalysisDomainTy::d_t;
53-
using n_t = typename AnalysisDomainTy::n_t;
54-
using f_t = typename AnalysisDomainTy::f_t;
55-
using t_t = typename AnalysisDomainTy::t_t;
56-
using v_t = typename AnalysisDomainTy::v_t;
57-
using l_t = typename AnalysisDomainTy::l_t;
58-
using i_t = typename AnalysisDomainTy::i_t;
59-
using db_t = typename AnalysisDomainTy::db_t;
60-
61-
using ConfigurationTy = HasNoConfigurationType;
62-
63-
using FlowFunctionType = FlowFunction<d_t>;
64-
using FlowFunctionPtrType = typename FlowFunctionType::FlowFunctionPtrType;
65-
6660
using IDETabulationProblem<AnalysisDomainTy>::IDETabulationProblem;
6761

6862
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/******************************************************************************
2+
* Copyright (c) 2025 Fabian Schiebel.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, mxHuber and others
8+
*****************************************************************************/
9+
10+
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_DEFAULTREACHABLEALLOCATIONSITESIDEPROBLEM_H
11+
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_DEFAULTREACHABLEALLOCATIONSITESIDEPROBLEM_H
12+
13+
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/DefaultNoAliasIDEProblem.h"
14+
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
15+
16+
// Forward declaration of types for which we only use its pointer or ref type
17+
namespace llvm {
18+
class Value;
19+
class Instruction;
20+
class Function;
21+
} // namespace llvm
22+
23+
namespace psr {
24+
25+
namespace detail {
26+
class IDEReachableAllocationSitesDefaultFlowFunctionsImpl
27+
: private IDENoAliasDefaultFlowFunctionsImpl {
28+
public:
29+
using typename IDENoAliasDefaultFlowFunctionsImpl::d_t;
30+
using typename IDENoAliasDefaultFlowFunctionsImpl::f_t;
31+
using typename IDENoAliasDefaultFlowFunctionsImpl::FlowFunctionPtrType;
32+
using typename IDENoAliasDefaultFlowFunctionsImpl::FlowFunctionType;
33+
using typename IDENoAliasDefaultFlowFunctionsImpl::n_t;
34+
35+
using IDENoAliasDefaultFlowFunctionsImpl::isFunctionModeled;
36+
37+
[[nodiscard]] constexpr LLVMAliasInfoRef getAliasInfo() const noexcept {
38+
return AS;
39+
}
40+
41+
constexpr IDEReachableAllocationSitesDefaultFlowFunctionsImpl(
42+
LLVMAliasInfoRef AS) noexcept
43+
: AS(AS) {
44+
assert(AS && "You must provide an alias information handle!");
45+
}
46+
47+
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunctionImpl(n_t Curr,
48+
n_t /*Succ*/);
49+
[[nodiscard]] FlowFunctionPtrType getCallFlowFunctionImpl(n_t CallInst,
50+
f_t CalleeFun);
51+
[[nodiscard]] FlowFunctionPtrType getRetFlowFunctionImpl(n_t CallSite,
52+
f_t /*CalleeFun*/,
53+
n_t ExitInst,
54+
n_t /*RetSite*/);
55+
56+
using IDENoAliasDefaultFlowFunctionsImpl::getCallToRetFlowFunctionImpl;
57+
58+
protected:
59+
LLVMAliasInfoRef AS;
60+
};
61+
} // namespace detail
62+
63+
template <typename AnalysisDomainTy>
64+
class DefaultReachableAllocationSitesIDEProblem
65+
: public IDETabulationProblem<AnalysisDomainTy>,
66+
protected detail::IDEReachableAllocationSitesDefaultFlowFunctionsImpl {
67+
public:
68+
using typename IDETabulationProblem<AnalysisDomainTy>::db_t;
69+
70+
/// Constructs an IDETabulationProblem with the usual arguments + alias
71+
/// information.
72+
///
73+
/// \note It is useful to use an instance of FilteredAliasSet for the alias
74+
/// information to lower suprious aliases
75+
explicit DefaultReachableAllocationSitesIDEProblem(
76+
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasInfoRef AS,
77+
std::vector<std::string> EntryPoints,
78+
std::optional<d_t>
79+
ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
80+
: IDETabulationProblem<AnalysisDomainTy>(IRDB, std::move(EntryPoints),
81+
ZeroValue),
82+
detail::IDEReachableAllocationSitesDefaultFlowFunctionsImpl(AS) {}
83+
84+
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
85+
n_t Succ) override {
86+
return getNormalFlowFunctionImpl(Curr, Succ);
87+
}
88+
89+
[[nodiscard]] FlowFunctionPtrType
90+
getCallFlowFunction(n_t CallInst, f_t CalleeFun) override {
91+
return getCallFlowFunctionImpl(CallInst, CalleeFun);
92+
}
93+
94+
[[nodiscard]] FlowFunctionPtrType getRetFlowFunction(n_t CallSite,
95+
f_t CalleeFun,
96+
n_t ExitInst,
97+
n_t RetSite) override {
98+
return getRetFlowFunctionImpl(CallSite, CalleeFun, ExitInst, RetSite);
99+
}
100+
101+
[[nodiscard]] FlowFunctionPtrType
102+
getCallToRetFlowFunction(n_t CallSite, n_t RetSite,
103+
llvm::ArrayRef<f_t> Callees) override {
104+
return getCallToRetFlowFunctionImpl(CallSite, RetSite, Callees);
105+
}
106+
};
107+
108+
class DefaultReachableAllocationSitesIFDSProblem
109+
: public IFDSTabulationProblem<LLVMIFDSAnalysisDomainDefault>,
110+
protected detail::IDEReachableAllocationSitesDefaultFlowFunctionsImpl {
111+
public:
112+
/// Constructs an IFDSTabulationProblem with the usual arguments + alias
113+
/// information.
114+
///
115+
/// \note It is useful to use an instance of FilteredAliasSet for the alias
116+
/// information to lower suprious aliases
117+
explicit DefaultReachableAllocationSitesIFDSProblem(
118+
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasInfoRef AS,
119+
std::vector<std::string> EntryPoints,
120+
d_t ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
121+
: IFDSTabulationProblem(IRDB, std::move(EntryPoints), ZeroValue),
122+
detail::IDEReachableAllocationSitesDefaultFlowFunctionsImpl(AS) {}
123+
124+
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
125+
n_t Succ) override {
126+
return getNormalFlowFunctionImpl(Curr, Succ);
127+
}
128+
129+
[[nodiscard]] FlowFunctionPtrType
130+
getCallFlowFunction(n_t CallInst, f_t CalleeFun) override {
131+
return getCallFlowFunctionImpl(CallInst, CalleeFun);
132+
}
133+
134+
[[nodiscard]] FlowFunctionPtrType getRetFlowFunction(n_t CallSite,
135+
f_t CalleeFun,
136+
n_t ExitInst,
137+
n_t RetSite) override {
138+
return getRetFlowFunctionImpl(CallSite, CalleeFun, ExitInst, RetSite);
139+
}
140+
141+
[[nodiscard]] FlowFunctionPtrType
142+
getCallToRetFlowFunction(n_t CallSite, n_t RetSite,
143+
llvm::ArrayRef<f_t> Callees) override {
144+
return getCallToRetFlowFunctionImpl(CallSite, RetSite, Callees);
145+
}
146+
};
147+
148+
} // namespace psr
149+
150+
#endif

include/phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/******************************************************************************
2+
* Copyright (c) 2025 Fabian Schiebel.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, bulletspace and others
8+
*****************************************************************************/
9+
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_FUNCTIONDATAFLOWFACTS_H
10+
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_FUNCTIONDATAFLOWFACTS_H
11+
112
#include "phasar/Utils/DefaultValue.h"
213

314
#include "llvm/ADT/StringMap.h"
@@ -75,3 +86,5 @@ class FunctionDataFlowFacts {
7586
};
7687

7788
} // namespace psr::library_summary
89+
90+
#endif // PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_FUNCTIONDATAFLOWFACTS_H

include/phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/******************************************************************************
2+
* Copyright (c) 2025 Fabian Schiebel.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, bulletspace and others
8+
*****************************************************************************/
9+
10+
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LLVMFUNCTIONDATAFLOWFACTS_H
11+
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LLVMFUNCTIONDATAFLOWFACTS_H
12+
113
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h"
214
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h"
315
#include "phasar/Utils/DefaultValue.h"
@@ -73,3 +85,5 @@ class LLVMFunctionDataFlowFacts {
7385
std::unordered_map<const llvm::Function *, ParameterMappingTy> LLVMFdff;
7486
};
7587
} // namespace psr::library_summary
88+
89+
#endif // PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LLVMFUNCTIONDATAFLOWFACTS_H
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
#pragma once
1+
/******************************************************************************
2+
* Copyright (c) 2025 Fabian Schiebel.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Fabian Schiebel, bulletspace and others
8+
*****************************************************************************/
9+
10+
#ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LIBCSUMMARY_H
11+
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LIBCSUMMARY_H
212

313
namespace psr {
414
namespace library_summary {
@@ -7,3 +17,5 @@ class FunctionDataFlowFacts;
717

818
[[nodiscard]] const library_summary::FunctionDataFlowFacts &getLibCSummary();
919
} // namespace psr
20+
21+
#endif // PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LIBCSUMMARY_H

lib/PhasarLLVM/DataFlow/IfdsIde/DefaultAliasAwareIDEFlowFunctions.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ auto detail::IDEAliasAwareDefaultFlowFunctionsImpl::getNormalFlowFunctionImpl(
3939
Curr, Succ);
4040
}
4141

42-
auto detail::IDEAliasAwareDefaultFlowFunctionsImpl::getCallFlowFunctionImpl(
43-
n_t CallInst, f_t CalleeFun) -> FlowFunctionPtrType {
44-
return this->IDENoAliasDefaultFlowFunctionsImpl::getCallFlowFunctionImpl(
45-
CallInst, CalleeFun);
46-
}
47-
4842
static void populateWithMayAliases(LLVMAliasInfoRef AS, container_type &Facts,
4943
const llvm::Instruction *Context) {
5044
container_type Tmp = Facts;
@@ -92,11 +86,3 @@ auto detail::IDEAliasAwareDefaultFlowFunctionsImpl::getRetFlowFunctionImpl(
9286

9387
return FFTemplates::killAllFlows();
9488
}
95-
96-
auto detail::IDEAliasAwareDefaultFlowFunctionsImpl::
97-
getCallToRetFlowFunctionImpl(n_t CallSite, n_t RetSite,
98-
llvm::ArrayRef<f_t> Callees)
99-
-> FlowFunctionPtrType {
100-
return this->IDENoAliasDefaultFlowFunctionsImpl::getCallToRetFlowFunctionImpl(
101-
CallSite, RetSite, Callees);
102-
}

0 commit comments

Comments
 (0)