-
Notifications
You must be signed in to change notification settings - Fork 13.4k
ManuallyDrop constructed with properly initialized data via MaybeUninit fails ASan #72154
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
Comments
Minimized test case (in terms of generated LLVM IR): pub struct Wrap {
pub t: [usize; 1]
}
impl Wrap {
#[inline(always)]
pub fn new(t: [usize; 1]) -> Self {
Wrap { t }
}
}
#[inline(always)]
pub fn assume_init() -> [usize; 1] {
[1234]
}
fn main() {
let x: [usize; 1] = assume_init();
Wrap::new(x);
} Sanitizer enables emissions of lifetime markers to detect use after scope bugs. Alloca for array in |
Is this actual UB that may be miscompiled, or just something the sanitizers complain about? |
If similar incorrect transformation were performed under different circumstances that could have quite bad consequences. At the same the impact of this particular issue is rather limited, since it requires opt-level=0 so that inliner does not introduce lifetime markers, and an enabled sanitizer so that lifetime markers are emitted during codegen (otherwise this happens only for opt-level != 0). |
The original code is technically speaking UB for calling |
Hi @RalfJung, I appreciate this is slightly off topic but could you clarify the UB in the original code? FWIU the |
Ah you are right, I misread. I didn't realize the |
Uh oh!
There was an error while loading. Please reload this page.
The minimum example I can get this down to is:
ASan output
Without the
ManuallyDrop
it is fine. The same code with regular initialization (noMaybeUninit
) does not cause ASan to fail.The above was run with rustc 1.45.0-nightly (99cb9cc 2020-05-11).
The text was updated successfully, but these errors were encountered: