Skip to content

CStr::from_bytes_with_nul(b"\0") return value changes when compiling with LTO #40165

Closed
@aprilwade

Description

@aprilwade

When compiling with LTO enabled, CStr::from_bytes_with_nul(b"\0") returns an error. Without LTO, it returns Ok. The former result seems incorrect. The following terminal session should help illustrate:

% cat testing.rs
use std::ffi::CStr;
fn main()
{
    println!("{:?}", CStr::from_bytes_with_nul(b"\0"));
}

% rustc testing.rs -C opt-level=3 -C lto

% ./testing
Err(FromBytesWithNulError { _a: () })

% rustc testing.rs -C opt-level=3

% ./testing
Ok("")

% rustc --version
rustc 1.15.1 (021bd294c 2017-02-08)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions