Skip to content

Commit

Permalink
hist: PR followups
Browse files Browse the repository at this point in the history
Fixes up some follow-on comments from [0].

Also fixes a compile time warning:

```
[25/85] Building CXX object src/CMakeFiles/runtime.dir/output.cpp.o
In file included from /usr/include/c++/13.2.1/cassert:44,
                 from /home/dxu/dev/bpftrace/src/log.h:3,
                 from /home/dxu/dev/bpftrace/src/output.cpp:3:
/home/dxu/dev/bpftrace/src/output.cpp: In static member function ‘static std::string bpftrace::TextOutput::hist_index_label(int, int)’:
/home/dxu/dev/bpftrace/src/output.cpp:53:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘const uint32_t’ {aka ‘const unsigned int’} [-Wsign-compare]
   53 |   assert(index >= n); // Smaller indexes are converted directly.
      |          ~~~~~~^~~~
```

[0]: bpftrace#2831 (comment)
  • Loading branch information
danobi committed Dec 26, 2023
1 parent 1c5fac1 commit a31d99c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ast/passes/resource_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ void ResourceAnalyser::visit(Call &call)
else if (call.func == "hist")
{
auto &r = resources_.hist_bits_arg;
int old, bits = static_cast<Integer *>(call.vargs->at(1))->n;
if (r.find(call.map->ident) != r.end() &&
(old = r[call.map->ident]) != bits)

int bits = static_cast<Integer *>(call.vargs->at(1))->n;
if (r.find(call.map->ident) != r.end() && (r[call.map->ident]) != bits)
{
LOG(ERROR, call.loc, err_)
<< "Different bits in a single hist, had " << old << " now " << bits;
LOG(ERROR, call.loc, err_) << "Different bits in a single hist, had "
<< r[call.map->ident] << " now " << bits;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::ostream& operator<<(std::ostream& out, MessageType type) {
std::string TextOutput::hist_index_label(int index, int k)
{
const uint32_t n = (1 << k), interval = index & (n - 1);
assert(index >= n); // Smaller indexes are converted directly.
assert(static_cast<uint32_t>(index) >= n); // Indicies are non-negative
uint32_t power = (index >> k) - 1;
// Choose the suffix for the largest power of 2^10
const uint32_t decade = power / 10;
Expand Down

0 comments on commit a31d99c

Please sign in to comment.