Skip to content

Commit 646a549

Browse files
Feature Taint Analysis (#738)
* Add feature-taint analysis (WIP) * gen from zero in CTR-EF * Add alloca flow * generate at fallback insts * Tie the EF semi-ring to the problem + integrate into solver * Incorporate combine and extend into IIA * minor * Make the FTaint Analysis work on the iia tests (not all pass, though) * Fix IIA * Fix call handling (TODO: Should we strong update pointer args?) * Rename FeatureTaintAnalysis to FeatureInteractionAnalysis * Add taints for args at callsite * Add FTaint Analysis to controller * rename * rename FIIA Domain * rename * Make PathSensitivityManagerMixin more self-contained * Fix top edge facts + further debugging * IMprove alias handling in store ff * Handle memset + add one more rvo test * cs taints do not hold within callees * Fix unionWith in IDEFeatureTaintEdgeFact * some cleanup * fix bugs introduced by merge * Start adding global_5 test * Add print on error to debug the ci * Start fixing CI for FIIA * Add missing ground-truth for FIIA RVO and Global * CI Fix for FIIA GlobalTest_05 * Fix buffer overflow * Update flaky tests * Fixes due to LLVM-15 IR * rename test fixture to IDEFeatureTaintAnalysisTest --------- Co-authored-by: Sriteja Kummita <sriteja.ku@gmail.com>
1 parent 58e367a commit 646a549

File tree

23 files changed

+1889
-68
lines changed

23 files changed

+1889
-68
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CheckOptions:
5959
- key: readability-identifier-naming.ParameterIgnoredRegexp
6060
value: (d|d1|d2|d3|d4|d5|eP|f|n)
6161
- key: readability-identifier-naming.FunctionIgnoredRegexp
62-
value: (try_emplace|from_json|to_json|equal_to|to_string|DToString|NToString|FToString|LToString)
62+
value: (try_emplace|from_json|to_json|equal_to|to_string|DToString|NToString|FToString|LToString|hash_value)
6363
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
6464
value: 1
6565
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions

include/phasar/DataFlow/IfdsIde/DefaultEdgeFunctionSingletonCache.h

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ namespace psr {
2222
/// hash_value(const EdgeFunctionTy&).
2323
///
2424
/// This cache is *not* thread-safe.
25-
template <typename EdgeFunctionTy, typename = void>
26-
class DefaultEdgeFunctionSingletonCache
25+
template <typename EdgeFunctionTy, typename L>
26+
class DefaultEdgeFunctionSingletonCacheImpl
2727
: public EdgeFunctionSingletonCache<EdgeFunctionTy> {
2828
public:
29-
DefaultEdgeFunctionSingletonCache() noexcept = default;
29+
DefaultEdgeFunctionSingletonCacheImpl() noexcept = default;
3030

31-
DefaultEdgeFunctionSingletonCache(const DefaultEdgeFunctionSingletonCache &) =
32-
delete;
33-
DefaultEdgeFunctionSingletonCache &
34-
operator=(const DefaultEdgeFunctionSingletonCache &) = delete;
31+
DefaultEdgeFunctionSingletonCacheImpl(
32+
const DefaultEdgeFunctionSingletonCacheImpl &) = delete;
33+
DefaultEdgeFunctionSingletonCacheImpl &
34+
operator=(const DefaultEdgeFunctionSingletonCacheImpl &) = delete;
3535

36-
DefaultEdgeFunctionSingletonCache(
37-
DefaultEdgeFunctionSingletonCache &&) noexcept = default;
38-
DefaultEdgeFunctionSingletonCache &
39-
operator=(DefaultEdgeFunctionSingletonCache &&) noexcept = delete;
40-
~DefaultEdgeFunctionSingletonCache() override = default;
36+
DefaultEdgeFunctionSingletonCacheImpl(
37+
DefaultEdgeFunctionSingletonCacheImpl &&) noexcept = default;
38+
DefaultEdgeFunctionSingletonCacheImpl &
39+
operator=(DefaultEdgeFunctionSingletonCacheImpl &&) noexcept = delete;
40+
~DefaultEdgeFunctionSingletonCacheImpl() override = default;
4141

4242
[[nodiscard]] const void *
43-
lookup(ByConstRef<EdgeFunctionTy> EF) const noexcept override {
43+
lookup(const EdgeFunctionTy &EF) const noexcept override {
4444
return Cache.lookup(&EF);
4545
}
4646

@@ -50,13 +50,10 @@ class DefaultEdgeFunctionSingletonCache
5050
assert(Inserted);
5151
}
5252

53-
void erase(ByConstRef<EdgeFunctionTy> EF) noexcept override {
54-
Cache.erase(&EF);
55-
}
53+
void erase(const EdgeFunctionTy &EF) noexcept override { Cache.erase(&EF); }
5654

5755
template <typename... ArgTys>
58-
[[nodiscard]] EdgeFunction<typename EdgeFunctionTy::l_t>
59-
createEdgeFunction(ArgTys &&...Args) {
56+
[[nodiscard]] EdgeFunction<L> createEdgeFunction(ArgTys &&...Args) {
6057
return CachedEdgeFunction<EdgeFunctionTy>{
6158
EdgeFunctionTy{std::forward<ArgTys>(Args)...}, this};
6259
}
@@ -92,19 +89,29 @@ class DefaultEdgeFunctionSingletonCache
9289
llvm::DenseMap<const EdgeFunctionTy *, const void *, DSI> Cache;
9390
};
9491

92+
template <typename EdgeFunctionTy, typename = void>
93+
class DefaultEdgeFunctionSingletonCache
94+
: public DefaultEdgeFunctionSingletonCacheImpl<
95+
EdgeFunctionTy, typename EdgeFunctionTy::l_t> {
96+
public:
97+
using DefaultEdgeFunctionSingletonCacheImpl<
98+
EdgeFunctionTy,
99+
typename EdgeFunctionTy::l_t>::DefaultEdgeFunctionSingletonCacheImpl;
100+
};
101+
95102
template <typename EdgeFunctionTy>
96103
class DefaultEdgeFunctionSingletonCache<
97104
EdgeFunctionTy,
98105
std::enable_if_t<EdgeFunctionBase::IsSOOCandidate<EdgeFunctionTy>>> {
99106
public:
100107
[[nodiscard]] const void *
101-
lookup(ByConstRef<EdgeFunctionTy> /*EF*/) const noexcept override {
108+
lookup(const EdgeFunctionTy & /*EF*/) const noexcept override {
102109
return nullptr;
103110
}
104111
void insert(const EdgeFunctionTy * /*EF*/, const void * /*Mem*/) override {
105112
assert(false && "We should never go here");
106113
}
107-
void erase(ByConstRef<EdgeFunctionTy> /*EF*/) noexcept override {
114+
void erase(const EdgeFunctionTy & /*EF*/) noexcept override {
108115
assert(false && "We should never go here");
109116
}
110117
[[nodiscard]] EdgeFunction<typename EdgeFunctionTy::l_t>

include/phasar/DataFlow/IfdsIde/EdgeFunctionSingletonCache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ template <typename EdgeFunctionTy> class EdgeFunctionSingletonCache {
4646
/// Checks whether the edge function EF is cached in this cache. Returns the
4747
/// cached entry if found, else nullptr.
4848
[[nodiscard]] virtual const void *
49-
lookup(ByConstRef<EdgeFunctionTy> EF) const noexcept = 0;
49+
lookup(const EdgeFunctionTy &EF) const noexcept = 0;
5050

5151
/// Inserts the cache-entry Mem for the edge function *EF into the cache.
5252
/// Typically, EF points into the buffer pointed to by Mem. Both pointers are
@@ -57,7 +57,7 @@ template <typename EdgeFunctionTy> class EdgeFunctionSingletonCache {
5757

5858
/// Erases the cache-entry associated with the edge function EF from the
5959
/// cache.
60-
virtual void erase(ByConstRef<EdgeFunctionTy> EF) noexcept = 0;
60+
virtual void erase(const EdgeFunctionTy &EF) noexcept = 0;
6161

6262
template <typename... ArgTys>
6363
[[nodiscard]] auto createEdgeFunction(ArgTys &&...Args) {

include/phasar/DataFlow/IfdsIde/FlowFunctions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,13 @@ template <typename D, typename Container> class FlowFunctionTemplates {
500500
struct GenManyAndKillAllOthers final
501501
: public FlowFunction<d_t, container_type> {
502502
GenManyAndKillAllOthers(Container &&GenValues, d_t FromValue)
503-
: GenValues(std::move(GenValues)), FromValue(std::move(FromValue)) {}
503+
: GenValues(std::move(GenValues)), FromValue(FromValue) {
504+
this->GenValues.insert(std::move(FromValue));
505+
}
504506

505507
container_type computeTargets(d_t Source) override {
506508
if (Source == FromValue) {
507-
auto Ret = GenValues;
508-
Ret.insert(std::move(Source));
509-
return Ret;
509+
return GenValues;
510510
}
511511
return {};
512512
}

include/phasar/DataFlow/IfdsIde/InitialSeeds.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define PHASAR_DATAFLOW_IFDSIDE_INITIALSEEDS_H
1212

1313
#include "phasar/Domain/BinaryDomain.h"
14+
#include "phasar/Utils/Printer.h"
1415
#include "phasar/Utils/TypeTraits.h"
1516

1617
#include "llvm/Support/Compiler.h"
@@ -75,36 +76,13 @@ template <typename N, typename D, typename L> class InitialSeeds {
7576
[[nodiscard]] GeneralizedSeeds getSeeds() && { return std::move(Seeds); }
7677

7778
void dump(llvm::raw_ostream &OS = llvm::errs()) const {
78-
79-
auto printNode = [&](auto &&Node) { // NOLINT
80-
if constexpr (std::is_pointer_v<N> &&
81-
is_llvm_printable_v<std::remove_pointer_t<N>>) {
82-
OS << *Node;
83-
} else {
84-
OS << Node;
85-
}
86-
};
87-
88-
auto printFact = [&](auto &&Node) { // NOLINT
89-
if constexpr (std::is_pointer_v<D> &&
90-
is_llvm_printable_v<std::remove_pointer_t<D>>) {
91-
OS << *Node;
92-
} else {
93-
OS << Node;
94-
}
95-
};
96-
9779
OS << "======================== Initial Seeds ========================\n";
9880
for (const auto &[Node, Facts] : Seeds) {
99-
OS << "At ";
100-
printNode(Node);
101-
OS << "\n";
81+
OS << "At " << NToString(Node) << '\n';
10282
for (const auto &[Fact, Value] : Facts) {
103-
OS << "> ";
104-
printFact(Fact);
105-
OS << " --> \\." << Value << "\n";
83+
OS << "> " << DToString(Fact) << " --> \\." << LToString(Value) << '\n';
10684
}
107-
OS << "\n";
85+
OS << '\n';
10886
}
10987
OS << "========================== End Seeds ==========================\n";
11088
}

include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@
2626
#include "llvm/ADT/SetVector.h"
2727
#include "llvm/ADT/SmallPtrSet.h"
2828
#include "llvm/ADT/SmallVector.h"
29+
#include "llvm/IR/IntrinsicInst.h"
2930
#include "llvm/Support/raw_ostream.h"
3031

3132
#include <cstdlib>
3233
#include <filesystem>
3334
#include <system_error>
3435
#include <type_traits>
3536

36-
namespace llvm {
37-
class DbgInfoIntrinsic;
38-
} // namespace llvm
39-
4037
namespace psr {
4138
template <typename Derived, typename AnalysisDomainTy, typename GraphType>
4239
class PathSensitivityManagerMixin {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_LLVMSOLVERRESULTS_H
1212

1313
#include "phasar/DataFlow/IfdsIde/SolverResults.h"
14+
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
1415
#include "phasar/Utils/JoinLattice.h"
1516
#include "phasar/Utils/Logger.h"
1617

0 commit comments

Comments
 (0)