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

Do not generate allocations for zero sized allocations #63635

Merged
merged 3 commits into from Aug 18, 2019

Conversation

@oli-obk
Copy link
Contributor

commented Aug 16, 2019

Alternative to #62487

r? @eddyb

There are other places where we could do this, too, but that would cause static FOO: () = (); to not have a unique address

@eddyb

This comment has been minimized.

Copy link
Member

commented Aug 16, 2019

Can you add a test, perhaps? Something that fails on master but passes with this change.

cc @scottmcm @nikomatsakis

&self.const_usize(offset.bytes()),
1,
)}
};
let llval = self.const_bitcast(llval, self.type_ptr_to(layout.llvm_type(self)));

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 16, 2019

Member

Could you move the bitcast to the non-zero-len arm? And compute this final pointer type only once?

)};
let llval = if layout.size == Size::ZERO {
let llval = self.const_usize(alloc.align.bytes());
unsafe { llvm::LLVMConstIntToPtr(llval, self.type_ptr_to(self.type_i8p())) }

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 16, 2019

Member

Also this seems like you're creating a i8** instead of i8* (but ideally we'd just go directly to the final type).

@scottmcm

This comment has been minimized.

Copy link
Member

commented Aug 17, 2019

Some easy, if indirect, tests:

    assert_eq!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
    assert_eq!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());
@oli-obk

This comment has been minimized.

Copy link
Contributor Author

commented Aug 17, 2019

Added tests and cleaned up the casting

@eddyb
eddyb approved these changes Aug 18, 2019
@eddyb

This comment has been minimized.

Copy link
Member

commented Aug 18, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2019

📌 Commit 1ea88a8 has been approved by eddyb

Centril added a commit to Centril/rust that referenced this pull request Aug 18, 2019
Rollup merge of rust-lang#63635 - oli-obk:default-slice-dangles, r=eddyb
Do not generate allocations for zero sized allocations

Alternative to rust-lang#62487

r? @eddyb

There are other places where we could do this, too, but that would cause `static FOO: () = ();` to not have a unique address
bors added a commit that referenced this pull request Aug 18, 2019
Auto merge of #63683 - Centril:rollup-pnig1vc, r=Centril
Rollup of 3 pull requests

Successful merges:

 - #61626 (Get rid of special const intrinsic query in favour of `const_eval`)
 - #63635 (Do not generate allocations for zero sized allocations)
 - #63659 (Improved error message for break in async block)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2019

⌛️ Testing commit 1ea88a8 with merge ea52be4...

bors added a commit that referenced this pull request Aug 18, 2019
Auto merge of #63635 - oli-obk:default-slice-dangles, r=eddyb
Do not generate allocations for zero sized allocations

Alternative to #62487

r? @eddyb

There are other places where we could do this, too, but that would cause `static FOO: () = ();` to not have a unique address
@bors

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2019

☀️ Test successful - checks-azure
Approved by: eddyb
Pushing ea52be4 to master...

@bors bors added the merged-by-bors label Aug 18, 2019

@bors bors merged commit 1ea88a8 into rust-lang:master Aug 18, 2019

5 checks passed

homu Test successful
Details
pr Build #20190817.8 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (LinuxTools) LinuxTools succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.