Skip to content

Commit

Permalink
Fix likely-invalid potential shift of int by >32 bits
Browse files Browse the repository at this point in the history
Signed-off-by: Mouse <[email protected]>
  • Loading branch information
mouse-mt authored and komaljai committed Dec 12, 2024
1 parent 9f67eb5 commit fc3cdd1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backends/ebpf/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ bool CodeGenInspector::preorder(const IR::Declaration_Variable *decl) {
return false;
}

// We count on the optimizer to get rid of 64-bit arithmetic when it's unnecessary
static cstring getMask(P4::TypeMap *typeMap, const IR::Node *node) {
auto type = typeMap->getType(node, true);
cstring mask = cstring::empty;
if (auto tb = type->to<IR::Type_Bits>()) {
if (tb->size != 8 && tb->size != 16 && tb->size != 32 && tb->size != 64)
mask = " & ((1 << " + Util::toString(tb->size) + ") - 1)";
mask = " & ((1ULL << " + Util::toString(tb->size) + ") - 1)";
}
return mask;
}
Expand Down

0 comments on commit fc3cdd1

Please sign in to comment.