Skip to content

Commit

Permalink
analyses: Add first form of UnitializedValues analysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
anthro-poid committed Jul 29, 2024
1 parent 4a3e507 commit 0acda7e
Show file tree
Hide file tree
Showing 6 changed files with 615 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/vast/Analyses/CFG.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

Check notice on line 1 in include/vast/Analyses/CFG.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/Analyses/CFG.hpp

File include/vast/Analyses/CFG.hpp does not conform to Custom style guidelines. (lines 5, 9, 10)

namespace vast::analyses {

class CFGBlock_T {
public:
unsigned BlockID;

unsigned getBlockID() const {
return BlockID;
}

explicit CFGBlock_T(unsigned blockid) : BlockID(blockid) {}
};

} // namespace vast::analyses
3 changes: 3 additions & 0 deletions include/vast/Analyses/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2024-present, Trail of Bits, Inc.

add_subdirectory(FlowSensitive)
1 change: 1 addition & 0 deletions include/vast/Analyses/FlowSensitive/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2024-present, Trail of Bits, Inc.
72 changes: 72 additions & 0 deletions include/vast/Analyses/FlowSensitive/DataflowWorklist.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2024-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Analyses/FlowSensitive/DataflowWorklist.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/Analyses/FlowSensitive/DataflowWorklist.hpp

File include/vast/Analyses/FlowSensitive/DataflowWorklist.hpp does not conform to Custom style guidelines. (lines 16, 18, 19, 20, 22, 43, 44, 55, 64)

#pragma once

#include "clang/Analysis/Analyses/IntervalPartition.h"
#include "clang/Analysis/Analyses/PostOrderCFGView.h"
#include "llvm/ADT/PriorityQueue.h"

#include "vast/Analyses/CFG.hpp"

Check failure on line 9 in include/vast/Analyses/FlowSensitive/DataflowWorklist.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

include/vast/Analyses/FlowSensitive/DataflowWorklist.hpp:9:10 [clang-diagnostic-error]

'vast/Analyses/CFG.hpp' file not found

namespace vast::analyses {

/// A worklist implementation where the enqueued blocks will be dequeued based
/// on the order defined by 'Comp'.
template< typename Comp, unsigned QueueSize, typename CFG_T, typename CFGBlock_T >
class DataflowWorklistBase {
llvm::BitVector EnqueuedBlocks;
llvm::PriorityQueue< const CFGBlock_T *,
llvm::SmallVector< const CFGBlock_T *, QueueSize >,
Comp > WorkList;
public:
DataflowWorklistBase(const CFG_T &Cfg, Comp C) : EnqueuedBlocks(Cfg.getNumBlockIDs()), WorkList(C) {}

void enqueueBlock(const CFGBlock_T *Block) {
if (Block && !EnqueuedBlocks[Block->getBlockID()]) {
EnqueuedBlocks[Block->getBlockID()] = true;
WorkList.push(Block);
}
}

const CFGBlock_T *dequeue() {
if (WorkList.empty()) {
return nullptr;
}
const CFGBlock_T *B = WorkList.top();
WorkList.pop();
EnqueuedBlocks[B->getBlockID()] = false;
return B;
}
};

template< typename CFGBlock_T >
struct ReversePostOrderCompare {
clang::PostOrderCFGView::BlockOrderCompare Cmp;
bool operator()(const CFGBlock_T *lhs, const CFGBlock_T *rhs) const {
return Cmp(rhs, lhs);
}
};

/// A worklist implementation for forward dataflow analysis. The enqueued
/// blocks will be dequeued in reverse post order. The worklist cannot contain
/// the same block multiple times at once.
template< typename CFG_T, typename CFGBlock_T, typename AnalysisDeclContext_T >
struct ForwardDataflowWorklist
: DataflowWorklistBase< ReversePostOrderCompare< CFGBlock_T >, 20, CFG_T, CFGBlock_T > {

/*
ForwardDataflowWorklist(const CFG_T &Cfg, PostOrderCFGView *POV)
: DataflowWorklistBase(Cfg,
ReversePostOrderCompare{POV->getComparator()}) {}
*/

ForwardDataflowWorklist(const CFG_T &Cfg, AnalysisDeclContext_T &Ctx)
: ForwardDataflowWorklist(Cfg, Ctx. template getAnalysis< clang::PostOrderCFGView >()) {}

void enqueueSuccessors(const CFGBlock_T *Block) {
for (auto B : Block->succs()) {
enqueueBlock(B);
}
}
};
} // namespace vast::analyses
Loading

0 comments on commit 0acda7e

Please sign in to comment.