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

LLVM abort with indexing of byte string literal in static #17233

Closed
huonw opened this issue Sep 13, 2014 · 7 comments
Closed

LLVM abort with indexing of byte string literal in static #17233

huonw opened this issue Sep 13, 2014 · 7 comments
Labels
A-DSTs Area: Dynamically-sized types (DSTs) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@huonw
Copy link
Member

huonw commented Sep 13, 2014

#![allow(dead_code)]

const X: &'static [u8] = b"1";

static Y: u8 = X[0];

fn main() {}
rustc: /build/rust-git/src/rust/src/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::GlobalVariable; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::GlobalVariable*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Aborted
playpen: application terminated with error code 134

Changing the b"1" to e.g. &[1] works fine.

@huonw huonw added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 13, 2014
@cristicbz
Copy link
Contributor

Also stumbled upon this. A workaround is using the bytes macro: bytes!("1")[0]

@Sawyer47
Copy link
Contributor

Current rust gives an error

5:20 error: cannot refer to other statics by value, use the address-of operator or a constant instead

@huonw
Copy link
Member Author

huonw commented Oct 16, 2014

Ah, thanks. It looks like this is still a problem after changing the static X to const Y.

@vadimcn
Copy link
Contributor

vadimcn commented Jan 23, 2015

Still seeing this, but bytes!() is gone now :(

@huonw
Copy link
Member Author

huonw commented Jan 24, 2015

This seems to be related to b"..." being a DST, that seemingly isn't being handled correctly, cc @nick29581. I think it would be fixed by #18465 but both @alexcrichton and I have met problems with implementing that.

@nrc nrc added the A-DSTs Area: Dynamically-sized types (DSTs) label Jan 27, 2015
bors added a commit that referenced this issue Mar 17, 2015
This patch changes the type of byte string literals from `&[u8]` to `&[u8; N]`.
It also implements some necessary traits (`IntoBytes`, `Seek`, `Read`, `BufRead`) for fixed-size arrays (also related to #21725) and adds test for #17233, which seems to be resolved.

Fixes #18465
[breaking-change]
bors added a commit that referenced this issue Mar 18, 2015
This patch changes the type of byte string literals from `&[u8]` to `&[u8; N]`.
It also implements some necessary traits (`IntoBytes`, `Seek`, `Read`, `BufRead`) for fixed-size arrays (also related to #21725) and adds test for #17233, which seems to be resolved.

Fixes #18465
[breaking-change]
@JustAPerson
Copy link
Contributor

This works fine now.

This issue may be closed.

@nrc
Copy link
Member

nrc commented Mar 29, 2015

Closed by #22838 (which even included a test :-) )

@nrc nrc closed this as completed Mar 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants