Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bpf_dins_pkt rewrite in BinaryOperator #1006

Merged
merged 1 commit into from
Mar 6, 2017

Conversation

pchaigno
Copy link
Contributor

@pchaigno pchaigno commented Feb 23, 2017

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 the
new 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

@pchaigno pchaigno force-pushed the fix-bpf_dins_pkt-rewrite branch 2 times, most recently from bc01474 to 95175b1 Compare February 27, 2017 21:27
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.

Replacing the whole binary operator expression with the call to
bpf_dins_pkt confuses the Rewriter and it is unable to track the new
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.
@pchaigno
Copy link
Contributor Author

pchaigno commented Mar 5, 2017

I've added a test case in test_clang.py based on @valkum's code in #537.

@drzaeus77 drzaeus77 merged commit 27a9cae into iovisor:master Mar 6, 2017
@drzaeus77
Copy link
Collaborator

Thanks!

@pchaigno pchaigno deleted the fix-bpf_dins_pkt-rewrite branch March 6, 2017 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing ')'
2 participants