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

Allow pointers to evaluate to true/false #3656

Merged
merged 1 commit into from
Dec 30, 2024
Merged

Conversation

amscanne
Copy link
Contributor

For if conditions, tenary expressions and logical expressions we can allow pointers to evaluate to true or false. This change updates the codegen to consistently use the null value for the lhs and rhs, and allows the appropriate conditions in the semantic analyzer. Runtime tests are added to ensure that the given programs evaluate to the expected outcomes.

This fixes #1579, but should only update #1726. The question of broader expanding logical operators to strings and other types is trickier, but the null value for pointers is fairly well-understood and a very common pattern for C programmers (who will often write these probes).

Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@amscanne amscanne force-pushed the truthy branch 2 times, most recently from 9b27524 to e7e630a Compare December 27, 2024 07:00
@amscanne amscanne marked this pull request as ready for review December 27, 2024 07:22
Copy link
Contributor

@jordalgo jordalgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! Nice work. Just a few minor changes needed.

CHANGELOG.md Outdated Show resolved Hide resolved
src/ast/passes/semantic_analyser.cpp Outdated Show resolved Hide resolved
tests/runtime/pointers Outdated Show resolved Hide resolved
Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but please add a few semantic analysis tests and a codegen test (just to get ahead of future regressions)

src/ast/passes/codegen_llvm.cpp Outdated Show resolved Hide resolved
@amscanne amscanne force-pushed the truthy branch 4 times, most recently from 6361560 to 27f3b70 Compare December 28, 2024 06:39
man/adoc/bpftrace.adoc Outdated Show resolved Hide resolved
For if conditions, tenary conditions and logical expressions we can
allow pointers to evaluate to true or false. This change updates the
codegen to consistently use the null value for the `lhs` and `rhs`, and
allows the appropriate conditions in the semantic analyzer. Runtime
tests are added to ensure that the given programs evaluate to the
expected outcomes.

This fixes bpftrace#1579, but should only update bpftrace#1726. The question of broader
expanding logical operators to strings and other types is trickier, but
the null value for pointers is fairly well-understood and a very common
pattern for C programmers (who will often write these probes).

The updates to documentation are minimal, as existing constraints are
not documented and it seems that using pointers generally matches user
expectations.
@jordalgo jordalgo merged commit 40a5cc8 into bpftrace:master Dec 30, 2024
18 checks passed
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.

Pointer type cannot be used with logical and
3 participants