Commit 4bb86107 authored by Matheus Marchini's avatar Matheus Marchini

[ast] fix str() to map assignment

Assigning the result of str() to a map broke after
https://github.com/iovisor/bpftrace/pull/299 landed. This commit fixes
it by making sure our call has a type before the final pass of the
semantic analyzer. Also moved the default strlen to bpftrace.h to make
sure the value is correctly set on unit tests.
parent edb26198
...@@ -226,8 +226,9 @@ void SemanticAnalyser::visit(Call &call) ...@@ -226,8 +226,9 @@ void SemanticAnalyser::visit(Call &call)
else if (call.func == "str") { else if (call.func == "str") {
if (check_varargs(call, 1, 2)) { if (check_varargs(call, 1, 2)) {
check_arg(call, Type::integer, 0); check_arg(call, Type::integer, 0);
if (is_final_pass()) {
uint64_t strlen = bpftrace_.strlen_; uint64_t strlen = bpftrace_.strlen_;
call.type = SizedType(Type::string, strlen);
if (is_final_pass()) {
if (call.vargs->size() > 1) { if (call.vargs->size() > 1) {
check_arg(call, Type::integer, 1, false); check_arg(call, Type::integer, 1, false);
auto &strlen_arg = *call.vargs->at(1); auto &strlen_arg = *call.vargs->at(1);
...@@ -235,7 +236,6 @@ void SemanticAnalyser::visit(Call &call) ...@@ -235,7 +236,6 @@ void SemanticAnalyser::visit(Call &call)
strlen = static_cast<Integer&>(strlen_arg).n; strlen = static_cast<Integer&>(strlen_arg).n;
} }
} }
call.type = SizedType(Type::string, strlen);
} }
} }
} }
......
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
int join_argnum_; int join_argnum_;
int join_argsize_; int join_argsize_;
uint64_t strlen_; uint64_t strlen_ = 64;
static void sort_by_key(std::vector<SizedType> key_args, static void sort_by_key(std::vector<SizedType> key_args,
std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> &values_by_key); std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> &values_by_key);
......
...@@ -180,7 +180,6 @@ int main(int argc, char *argv[]) ...@@ -180,7 +180,6 @@ int main(int argc, char *argv[])
bpftrace.join_argnum_ = 16; bpftrace.join_argnum_ = 16;
bpftrace.join_argsize_ = 1024; bpftrace.join_argsize_ = 1024;
bpftrace.strlen_ = 64;
if(const char* env_p = std::getenv("BPFTRACE_STRLEN")) { if(const char* env_p = std::getenv("BPFTRACE_STRLEN")) {
uint64_t proposed; uint64_t proposed;
std::istringstream stringstream(env_p); std::istringstream stringstream(env_p);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment