Skip to content

Non-primitive-types static assertions result in an LLVM failure #22056

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
LeoTestard opened this issue Feb 7, 2015 · 2 comments · Fixed by #22907
Closed

Non-primitive-types static assertions result in an LLVM failure #22056

LeoTestard opened this issue Feb 7, 2015 · 2 comments · Fixed by #22907
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@LeoTestard
Copy link
Contributor

The code:

struct S;

#[static_assert]
static FOO: S = S;

fn main() {}

results in:

issue-13951.rs:1:1: 1:10 warning: struct is never used: `S`, #[warn(dead_code)] on by default
issue-13951.rs:1 struct S;
                 ^~~~~~~~~
issue-13951.rs:4:1: 4:19 warning: static item is never used: `FOO`, #[warn(dead_code)] on by default
issue-13951.rs:4 static FOO: S = S;
                 ^~~~~~~~~~~~~~~~~~
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::ConstantInt; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::ConstantInt*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

This has no meaning and should be at least warned about. Putting #[static_assert] on non-static items (like struct definitions... ) is silently ignored.
I think that we should restrict #[static_assert] to boolean statics, and emit a warning or an error in the other cases.

@LeoTestard
Copy link
Contributor Author

(I think I can fix this myself, actually I found this while trying to fix #13951 and it's a bit blocking since I don't know which #[static_assert]-flagged statics considered as used or not. But I just need someone from the team to agree or not that we should disallow such statics.)

@kmcallister kmcallister added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Feb 7, 2015
@dotdash
Copy link
Contributor

dotdash commented Feb 19, 2015

IMO, it's not so much about allowing such statics but about allowing #[static_assert] on statics that aren't plain integers. You get the same assertion with struct S { x: i32 }, and we surely want to allow such statics.

As far as I'm concerned, I'd forbid #![static_assert] on such statics.

dotdash added a commit to dotdash/rust that referenced this issue Feb 28, 2015
static_assert is documented as working on static with type `bool`, but
we currently accept it on any const static and crash when the const has
an non-integral type.

This is a breaking-change for anyone who used static_assert on types
likes i32, which happened to work but seems like an unintended
consequence of the missing error checking.

[breaking-change]

Fixes rust-lang#22056
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 28, 2015
 static_assert is documented as working on static with type `bool`, but
we currently accept it on any const static and crash when the const has
an non-integral type.

This is a breaking-change for anyone who used static_assert on types
likes i32, which happened to work but seems like an unintended
consequence of the missing error checking.

[breaking-change]

Fixes rust-lang#22056
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 1, 2015
 static_assert is documented as working on static with type `bool`, but
we currently accept it on any const static and crash when the const has
an non-integral type.

This is a breaking-change for anyone who used static_assert on types
likes i32, which happened to work but seems like an unintended
consequence of the missing error checking.

[breaking-change]

Fixes rust-lang#22056
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants