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

stage2: implement ** and ++ at runtime #9876

Closed
wants to merge 4 commits into from
Closed

Conversation

g-w1
Copy link
Contributor

@g-w1 g-w1 commented Oct 1, 2021

No description provided.

@g-w1 g-w1 marked this pull request as ready for review October 2, 2021 22:06
@g-w1 g-w1 changed the title stage2: implement ** at runtime stage2: implement ** and ++ at runtime Oct 2, 2021
src/Sema.zig Show resolved Hide resolved
@g-w1 g-w1 marked this pull request as draft October 3, 2021 00:30
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

In your crash screenshot, the Value object that has a bad memory reference is coming from a Decl's Value. Check the Decl name in a debugger and figure out why that Decl's Value is invalid.

src/Sema.zig Show resolved Hide resolved
src/Sema.zig Outdated Show resolved Hide resolved
@g-w1
Copy link
Contributor Author

g-w1 commented Oct 3, 2021

I stubbed the case that causes the uaf out as a TODO for now as it is confusing me.

@g-w1 g-w1 marked this pull request as ready for review October 3, 2021 13:25
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

Can you please rebase this against master? I just pushed 3b2e25e which adds a missed copy() on the sentinel value and the element type.

src/Sema.zig Outdated Show resolved Hide resolved
@g-w1
Copy link
Contributor Author

g-w1 commented Oct 21, 2021

Thanks for fixing the uaf!

@g-w1 g-w1 force-pushed the runn branch 3 times, most recently from 97641f8 to 71c902b Compare October 22, 2021 23:30
src/Sema.zig Outdated
const alloc = try block.addTy(.alloc, ptr_ty);

try sema.requireRuntimeBlock(block, lhs_src);
if (mulinfo.len * mulinfo.elem_type.abiSize(sema.mod.getTarget()) <= 65535) { // if its less than the max integer size, we can bitcast it to an int
Copy link
Member

Choose a reason for hiding this comment

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

This logic has to do with the limitations of the LLVM backend, specifically, right?

The AIR memset instruction is perfectly capable of representing any sized element. The LLVM backend can do this logic of checking for 65535, and the other backends can choose a different strategy for lowering the AIR instruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the zig language requires that ints have bits <= 65535, so it may be because of llvm, but llvm is not the only reason, it's the zig spec.

Copy link
Member

Choose a reason for hiding this comment

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

Why integers? The element type of an array could be many other types besides integers

ptr_elem_ptr is a ty_pl, not bin_op
also use usize instead of u64
@g-w1
Copy link
Contributor Author

g-w1 commented Oct 23, 2021

Ok, marking as draft as memset with bitcast is being weird in llvm backend.

@g-w1 g-w1 marked this pull request as draft October 23, 2021 00:29
@andrewrk
Copy link
Member

andrewrk commented Jan 8, 2022

30+ days old draft; closing.

@andrewrk andrewrk closed this Jan 8, 2022
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.

None yet

2 participants