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 === and objectid of object with potentially undef inline immutable field #37557

Merged
merged 1 commit into from
Sep 16, 2020

Conversation

yuyichao
Copy link
Contributor

@yuyichao yuyichao commented Sep 13, 2020

An undef field should always be treated equal to another undef field of the same type
since there's no other way for the user to tell the difference between these.
These could previously cause inconsistent comparison results or crashes.

  • Mark these types as haspadding so that they'll not hit the memcmp fast path.

  • Make sure jl_egal and jl_object_id_ doesn't read bits fields in undef inline immutable field

  • Use emit_getfield_knownidx in emit_bits_compare so that the check can be done more easily

    Handle union fields of the same type in emit_f_isa to avoid regression.

  • Allow input to emit_f_isa to be NULL and lazily emit NULL check if necessary

@yuyichao yuyichao added compiler:codegen Generation of LLVM IR and native code backport 1.5 labels Sep 13, 2020
@yuyichao
Copy link
Contributor Author

This is what led to #37511 and depends on #37511 . It came out of an attempt to reuse getfield in codegen for emitting === to make other optimizations easier which is why the fix is like this. It's probably possible to create a more backportable version without this part of the change (i.e. only touch emit_bits_compare) but it'll be more annoy to do. We'll see if this is too hard to backport = = ...

src/codegen.cpp Outdated

// TODO: handle the case where arg1.typ != arg2.typ, or when one of these isn't union,
// or when the union can be pointer
if (arg1.TIndex && arg2.TIndex && arg1.typ == arg2.typ &&
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (arg1.TIndex && arg2.TIndex && arg1.typ == arg2.typ &&
if (arg1.TIndex && arg2.TIndex && jl_egal(arg1.typ, arg2.typ) &&

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume so is the assert in the callee.

An undef field should always be treated equal to another undef field of the same type
since there's no other way for the user to tell the difference between these.
These could previously cause inconsistent comparison results or crashes.

* Mark these types as `haspadding` so that they'll not hit the `memcmp` fast path.
* Make sure `jl_egal` and `jl_object_id_` doesn't read bits fields in undef inline immutable field
* Use `emit_getfield_knownidx` in `emit_bits_compare` so that the check can be done more easily

    Handle union fields of the same type in `emit_f_isa` to avoid regression.

* Allow input to `emit_f_isa` to be NULL and lazily emit NULL check if necessary
@yuyichao yuyichao merged commit e84fec4 into master Sep 16, 2020
@yuyichao yuyichao deleted the yyc/codegen/cmp branch September 16, 2020 12:34
@KristofferC KristofferC mentioned this pull request Oct 21, 2020
15 tasks
@vchuravy vchuravy mentioned this pull request Jan 21, 2021
27 tasks
vchuravy pushed a commit that referenced this pull request Jan 22, 2021
)

An undef field should always be treated equal to another undef field of the same type
since there's no other way for the user to tell the difference between these.
These could previously cause inconsistent comparison results or crashes.

* Mark these types as `haspadding` so that they'll not hit the `memcmp` fast path.
* Make sure `jl_egal` and `jl_object_id_` doesn't read bits fields in undef inline immutable field
* Use `emit_getfield_knownidx` in `emit_bits_compare` so that the check can be done more easily

    Handle union fields of the same type in `emit_f_isa` to avoid regression.

* Allow input to `emit_f_isa` to be NULL and lazily emit NULL check if necessary

(cherry picked from commit e84fec4)
vchuravy pushed a commit that referenced this pull request Jan 22, 2021
)

An undef field should always be treated equal to another undef field of the same type
since there's no other way for the user to tell the difference between these.
These could previously cause inconsistent comparison results or crashes.

* Mark these types as `haspadding` so that they'll not hit the `memcmp` fast path.
* Make sure `jl_egal` and `jl_object_id_` doesn't read bits fields in undef inline immutable field
* Use `emit_getfield_knownidx` in `emit_bits_compare` so that the check can be done more easily

    Handle union fields of the same type in `emit_f_isa` to avoid regression.

* Allow input to `emit_f_isa` to be NULL and lazily emit NULL check if necessary

(cherry picked from commit e84fec4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants