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

Unify and fix string comparison codegen #1979

Merged
merged 1 commit into from
Aug 26, 2021

Conversation

viktormalik
Copy link
Contributor

@viktormalik viktormalik commented Aug 23, 2021

Fixes #1978.

There were two versions of string comparison codegen (CreateStrncmp) - one for comparing two on-stack strings and one for comparing an on-stack string with a string literal. The version for comparing with literals was wrong and caused the linked bug.

This PR unifies the two functions into one and fixes the bug.

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

There were two versions of string comparison codegen (CreateStrncmp) -
one for comparing two on-stack strings and one for comparing an on-stack
string with a string literal. The version for comparing with literals
contained a bug which caused two non-equal strings where one is a prefix
of the other to be compaed as equal.

This commit unifies the two functions into one and fixes the bug. Also,
it adds a number of runtime tests that previously did not pass.

Note: the expected result of one existing test was changed since the
tested behaviour of strncmp did not match the behaviour of C's strncmp.
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.

Nice! Thanks


assert(val1p->getElementType()->isArrayTy() &&
val1p->getElementType()->getArrayElementType() == getInt8Ty());
#ifndef NDEBUG
Copy link
Member

Choose a reason for hiding this comment

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

Should it be #ifdef NDEBUG instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I just used what was originally there, but I think that it's correct: if NDEBUG is defined (i.e. debug mode is off), don't run the assertions.

@danobi danobi merged commit ce57bc8 into bpftrace:master Aug 26, 2021
@viktormalik viktormalik deleted the strcmp-fix branch November 24, 2021 12:30
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.

Incorrect string literal comparisons
3 participants