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

Uninitialized bytes get copied to the buffer when creating an uninitialized tuple #83087

Closed
MSxDOS opened this issue Mar 13, 2021 · 6 comments
Closed
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-slow Issue: Problems and improvements with respect to performance of generated code. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@MSxDOS
Copy link

MSxDOS commented Mar 13, 2021

In this example:

use std::mem::MaybeUninit;

extern {
    fn fill(p: *mut u16);
}

pub unsafe fn test() {
    let (mut buffer, mut buffer2): ([u16; 512], [u16; 256]) = MaybeUninit::uninit().assume_init();
    fill(buffer.as_mut_ptr());
    fill(buffer2.as_mut_ptr())
}

there is a call to memcpy for one of the buffers that copies uninitialized data to it.
https://rust.godbolt.org/z/z1zcor

@MSxDOS
Copy link
Author

MSxDOS commented Mar 13, 2021

cc @nikic

This started after #82806 was merged.

Also, this is a regression from stable to nightly.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-slow Issue: Problems and improvements with respect to performance of generated code. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 13, 2021
@nikic nikic self-assigned this Mar 13, 2021
@nikic
Copy link
Contributor

nikic commented Mar 13, 2021

Upstream fix: llvm/llvm-project@5556660

@pietroalbini pietroalbini added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels May 4, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 4, 2021
@pietroalbini pietroalbini added this to the 1.52.0 milestone May 4, 2021
@pietroalbini
Copy link
Member

This slipped up to stable 1.52.0, apparently we didn't label it regression-from-stable-to-beta losing track of it :/

@nikic
Copy link
Contributor

nikic commented May 4, 2021

@pietroalbini We don't plan to address this prior to the next LLVM upgrade anyway. It's just an optimization issue.

@apiraino
Copy link
Contributor

apiraino commented May 6, 2021

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-high +T-compiler

@rustbot rustbot added P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 6, 2021
@nikic
Copy link
Contributor

nikic commented Aug 22, 2021

Fixed by #87570, new IR does not have memcpy:

define void @_ZN5test24test17h0962739e00df972bE() unnamed_addr #0 {
start:
  %buffer2 = alloca [256 x i16], align 2
  %buffer = alloca [512 x i16], align 2
  %0 = bitcast [512 x i16]* %buffer to i8*
  call void @llvm.lifetime.start.p0i8(i64 1024, i8* nonnull %0)
  %1 = bitcast [256 x i16]* %buffer2 to i8*
  call void @llvm.lifetime.start.p0i8(i64 512, i8* nonnull %1)
  %2 = getelementptr inbounds [512 x i16], [512 x i16]* %buffer, i64 0, i64 0
  call void @fill(i16* nonnull %2)
  %3 = getelementptr inbounds [256 x i16], [256 x i16]* %buffer2, i64 0, i64 0
  call void @fill(i16* nonnull %3)
  call void @llvm.lifetime.end.p0i8(i64 512, i8* nonnull %1)
  call void @llvm.lifetime.end.p0i8(i64 1024, i8* nonnull %0)
  ret void
}

@nikic nikic closed this as completed Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-slow Issue: Problems and improvements with respect to performance of generated code. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants