Fix bpf_dins_pkt rewrite in BinaryOperator #1006
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes #537 by changing the way
BinaryOperator
expressions are rewritten.
Binary operator expressions where the left hand-side expression is a
reference to the packet are replaced by a call to the
bpf_dins_pkt
helper. When replacing text, the Clang Rewriter tries to maintain a
list of offsets between the original and the new position of tokens.
However, replacing the whole binary operator expression with the call
to
bpf_dins_pkt
confuses the Rewriter and it is unable to track thenew position of the right hand-side expression. Rewriting the binary
operator expression in two times without rewriting the right
hand-side expression itself solves the issue.
I believe the second issue reported in #537 by @mvbpolito is a
different bug. It's specific to the use of a constant in a rewritten
expression. The constant seems "invisible" to the Clang rewriter.
I haven't found a proper way to fix it yet.See #1008./cc @drzaeus77 @valkum