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

Compiler assertion failure with -O, zero-size struct, and NonCopyable #10028

Closed
MicahChalmer opened this issue Oct 23, 2013 · 3 comments · Fixed by #12738
Closed

Compiler assertion failure with -O, zero-size struct, and NonCopyable #10028

MicahChalmer opened this issue Oct 23, 2013 · 3 comments · Fixed by #12738
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@MicahChalmer
Copy link
Contributor

This program:

use std::util::NonCopyable;
struct Foo {
    nocopies: NonCopyable
}

fn make_foo() -> Foo {
    Foo { nocopies: NonCopyable::new() }
}

fn main() {
    let _f:Foo = make_foo();
}

will cause the compiler to crash and print this when compiled with -O:

Assertion failed: (begin() + idx < end()), function operator[], file /Users/micah/progs/rust/src/llvm/include/llvm/ADT/SmallVector.h, line 140.
Stack dump:
0.  Running pass 'Function Pass Manager' on module 'dag_dawg.rc'.
1.  Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN4main19heaa017369cfad4b1ar4v0.0E'

(dag_dawg.rs was the file name I tried to compile.) Without -O it compiles fine. If you replace NonCopyable::new() with just NonCopyable it compiles fine, suggesting that NonCopyable::new() itself is no longer even necessary.

I created my own version of NonCopyable in another crate and linked to it. The crash reproduced only if, like std::NonCopyable, my struct had the attribute #[unsafe_no_drop_flag].

Add a non-zero-length field to the struct and the crash goes away.

@sanxiyn
Copy link
Member

sanxiyn commented Jan 17, 2014

NonCopyable::new was removed in #10575. Can you provide a test case not depending on NonCopyable::new?

@MicahChalmer
Copy link
Contributor Author

Yup, I can still reproduce it. You need two files for it. The first is a library crate, which compiles fine--let's call it issue10028.rs:

#[crate_type="lib"];

#[unsafe_no_drop_flag]
pub struct ZeroLengthThingWithDestructor;
impl Drop for ZeroLengthThingWithDestructor {
    fn drop(&mut self) {}
}
impl ZeroLengthThingWithDestructor {
    pub fn new() -> ZeroLengthThingWithDestructor {
        ZeroLengthThingWithDestructor
    }
}

The library crate compiles fine. Now try to compile this file that uses it with rustc -O (allowing it to find the library built from above) and you'll see the same ICE described above:

extern mod issue10028;
use issue10028::ZeroLengthThingWithDestructor;

struct Foo {
    zero_length_thing: ZeroLengthThingWithDestructor
}

fn make_foo() -> Foo {
    Foo { zero_length_thing: ZeroLengthThingWithDestructor::new() }
}

fn main() {
    let _f:Foo = make_foo();
}

This is basically the same test case I had before--I just replaced NonCopyable with another struct that is the same as the old NonCopyable before the new method was eliminated.

If you combine them into the same crate (even issue10028.rs is still its own file as a module) then the problem does not occur. It has to be in a separate crate from the one being compiled.

@alexcrichton
Copy link
Member

This has been fixed, flagging as needstest

bors added a commit that referenced this issue Mar 6, 2014
Closes #6738
Closes #7061
Closes #7899
Closes #9719
Closes #10028
Closes #10228
Closes #10401
Closes #11192
Closes #11508
Closes #11529
Closes #11873
Closes #11925
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 10, 2023
…ers, r=flip1995

Add `extra_unused_type_parameters` lint

Closes rust-lang#9240. ~~Keeping this as draft for now, because of a bug that I don't know how to fix.~~ It seems that opaque return types are not walked properly, for some unknown reason. As in, the following:

```rust
fn used_ret_opaque<A>() -> impl Iterator<Item = A> {
    std::iter::empty()
}
```
This triggers the lint even though it shouldn't. Discussion on Zulip didn't illuminate any possible reasons why, so PR-ing this now to increase visibility.

---

changelog: new lint: [`extra_unused_type_parameters`]
[rust-lang#10028](rust-lang/rust-clippy#10028)
<!-- changelog_checked -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants