Skip to content

Commit

Permalink
more consts
Browse files Browse the repository at this point in the history
Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Nov 7, 2024
1 parent 9d02903 commit 69d51ab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ class AssertExtractor {
explicit AssertExtractor(program_info info, std::optional<label_t> label)
: info{std::move(info)}, current_label(label) {}

vector<Assert> operator()(Undefined const&) const {
vector<Assert> operator()(const Undefined&) const {
assert(false);
return {};
}

vector<Assert> operator()(Assert const&) const {
vector<Assert> operator()(const Assert&) const {
assert(false);
return {};
}

vector<Assert> operator()(IncrementLoopCounter& ipc) const { return {{BoundedLoopCount{ipc.name}}}; }
vector<Assert> operator()(const IncrementLoopCounter& ipc) const { return {{BoundedLoopCount{ipc.name}}}; }

vector<Assert> operator()(LoadMapFd const&) const { return {}; }
vector<Assert> operator()(const LoadMapFd&) const { return {}; }

/// Packet access implicitly uses R6, so verify that R6 still has a pointer to the context.
vector<Assert> operator()(Packet const&) const { return zero_offset_ctx({6}); }
vector<Assert> operator()(const Packet&) const { return zero_offset_ctx({6}); }

vector<Assert> operator()(Exit const&) const {
vector<Assert> operator()(const Exit&) const {
vector<Assert> res;
if (current_label->stack_frame_prefix.empty()) {
// Verify that Exit returns a number.
Expand All @@ -63,7 +63,7 @@ class AssertExtractor {
return res;
}

vector<Assert> operator()(Call const& call) const {
vector<Assert> operator()(const Call& call) const {
vector<Assert> res;
std::optional<Reg> map_fd_reg;
res.emplace_back(ValidCall{call.func, call.stack_frame_prefix});
Expand Down Expand Up @@ -120,9 +120,9 @@ class AssertExtractor {
return res;
}

vector<Assert> operator()(CallLocal const& call) const { return {}; }
vector<Assert> operator()(const CallLocal&) const { return {}; }

vector<Assert> operator()(Callx const& callx) const {
vector<Assert> operator()(const Callx& callx) const {
vector<Assert> res;
res.emplace_back(TypeConstraint{callx.func, TypeGroup::number});
res.emplace_back(FuncConstraint{callx.func});
Expand Down Expand Up @@ -229,7 +229,7 @@ class AssertExtractor {
};
}

vector<Assert> operator()(const Un ins) const { return {Assert{TypeConstraint{ins.dst, TypeGroup::number}}}; }
vector<Assert> operator()(const Un& ins) const { return {Assert{TypeConstraint{ins.dst, TypeGroup::number}}}; }

vector<Assert> operator()(const Bin& ins) const {
switch (ins.op) {
Expand Down Expand Up @@ -303,7 +303,7 @@ void explicate_assertions(cfg_t& cfg, const program_info& info) {
for (auto& [label, bb] : cfg) {
(void)label; // unused
vector<Instruction> insts;
for (const auto& ins : vector(bb.begin(), bb.end())) {
for (const auto& ins : bb) {
for (const auto& a : get_assertions(ins, info, bb.label())) {
insts.emplace_back(a);
}
Expand Down
10 changes: 5 additions & 5 deletions src/crab/cfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ class cfg_t final {
}

//! return a begin iterator of label_t's
label_iterator label_begin() { return boost::make_transform_iterator(m_blocks.begin(), get_label()); }
const_label_iterator label_begin() { return boost::make_transform_iterator(m_blocks.begin(), get_label()); }

//! return an end iterator of label_t's
label_iterator label_end() { return boost::make_transform_iterator(m_blocks.end(), get_label()); }
const_label_iterator label_end() { return boost::make_transform_iterator(m_blocks.end(), get_label()); }

//! return a begin iterator of label_t's
[[nodiscard]]
Expand All @@ -387,7 +387,7 @@ class cfg_t final {
}

void simplify() {
std::set<label_t> worklist(this->label_begin(), this->label_end());
std::set worklist(this->label_begin(), this->label_end());
while (!worklist.empty()) {
label_t label = *worklist.begin();
worklist.erase(label);
Expand Down Expand Up @@ -556,9 +556,9 @@ class cfg_rev_t final {
return _rev_bbs.end();
}

label_iterator label_begin() const { return _cfg.label_begin(); }
const_label_iterator label_begin() const { return _cfg.label_begin(); }

label_iterator label_end() const { return _cfg.label_end(); }
const_label_iterator label_end() const { return _cfg.label_end(); }

[[nodiscard]]
label_t exit_label() const {
Expand Down
2 changes: 1 addition & 1 deletion src/crab_utils/adapt_sgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class AdaptGraph final {
g.growTo(o.size());

for (vert_id s : o.verts()) {
for (const auto e : o.e_succs(s)) {
for (const auto& e : o.e_succs(s)) {
g.add_edge(s, e.val, e.vert);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ using std::string;
using std::vector;

static size_t hash(const raw_program& raw_prog) {
char* start = (char*)raw_prog.prog.data();
char* end = start + (raw_prog.prog.size() * sizeof(ebpf_inst));
const char* start = reinterpret_cast<const char*>(raw_prog.prog.data());
const char* end = start + raw_prog.prog.size() * sizeof(ebpf_inst);
return boost::hash_range(start, end);
}

Expand Down Expand Up @@ -53,7 +53,7 @@ static std::set<std::string> _get_conformance_group_names() {
return result;
}

static std::optional<raw_program> find_program(vector<raw_program>& raw_progs, std::string desired_program) {
static std::optional<raw_program> find_program(vector<raw_program>& raw_progs, const std::string& desired_program) {
if (desired_program.empty() && raw_progs.size() == 1) {
// Select the last program section.
return raw_progs.back();
Expand All @@ -66,7 +66,7 @@ static std::optional<raw_program> find_program(vector<raw_program>& raw_progs, s
return {};
}

int main(int argc, char** argv) {
int main(const int argc, char** argv) {
// Always call ebpf_verifier_clear_thread_local_state on scope exit.
at_scope_exit<ebpf_verifier_clear_thread_local_state> clear_thread_local_state;

Expand Down
8 changes: 4 additions & 4 deletions src/test/test_conformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#define CONFORMANCE_TEST_PATH "external/bpf_conformance/tests/"

static void test_conformance(std::string filename, bpf_conformance_test_result_t expected_result,
std::string expected_reason) {
static void test_conformance(const std::string& filename, bpf_conformance_test_result_t expected_result,
const std::string& expected_reason) {
std::vector<std::filesystem::path> test_files = {CONFORMANCE_TEST_PATH + filename};
boost::filesystem::path test_path = boost::dll::program_location();
boost::filesystem::path extension = test_path.extension();
std::filesystem::path plugin_path =
const boost::filesystem::path extension = test_path.extension();
const std::filesystem::path plugin_path =
test_path.remove_filename().append("conformance_check" + extension.string()).string();
std::map<std::filesystem::path, std::tuple<bpf_conformance_test_result_t, std::string>> result =
bpf_conformance(test_files, plugin_path, {}, {}, {}, bpf_conformance_test_CPU_version_t::v4,
Expand Down

0 comments on commit 69d51ab

Please sign in to comment.