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

virtual function elimination: llvm error: Do not know how to promote this operator #124093

Open
matthiaskrgr opened this issue Apr 17, 2024 · 1 comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

pub mod kitty {
    use std::fmt;

    pub struct cat {
        meows: usize,
        pub how_hungry: isize,
        pub name: String,
    }

    impl fmt::Display for cat {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{}", self.name)
        }
    }
}
original code

original:

pub mod kitty {
    use std::fmt;

    pub struct cat {
      meows : usize,
      pub how_hungry : isize,
      pub name : String,
    }

    impl fmt::Display for cat {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{}", self.name)
        }
    }

    impl cat {
        fn meow(&mut self) {
            println!("Meow");
            self.meows += 1;
            if self.meows % 5 == 0 {
                self.how_hungry += 1;
            }
        }

    }

    impl cat {
        pub fn speak(&mut self) { self.meow(); }

        pub fn eat(&mut self) -> bool {
            if self.how_hungry > 0 {
                println!("OM NOM NOM");
                self.how_hungry -= 2;
                return true;
            }
            else {
                println!("Not hungry!");
                return false;
            }
        }
    }

    pub fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
        cat {
            meows: in_x,
            how_hungry: in_y,
            name: in_name
        }
    }
}

Version information

rustc 1.79.0-nightly (00ed4edb4 2024-04-17)
binary: rustc
commit-hash: 00ed4edb44ccc76d8cc992ef9f9f4634ea6d0e82
commit-date: 2024-04-17
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zvirtual-function-elimination=true -Clto=true --crate-type=lib

Program output

warning: type `cat` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.8xGPA271RB07/rustc_testrunner_tmpdir_reporting.GzzcQXIiIZoj/mvce.rs:4:16
  |
4 |     pub struct cat {
  |                ^^^ help: convert the identifier to upper camel case (notice the capitalization): `Cat`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: field `meows` is never read
 --> /tmp/icemaker_global_tempdir.8xGPA271RB07/rustc_testrunner_tmpdir_reporting.GzzcQXIiIZoj/mvce.rs:5:9
  |
4 |     pub struct cat {
  |                --- field in this struct
5 |         meows: usize,
  |         ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

rustc-LLVM ERROR: Do not know how to promote this operator!

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Apr 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 17, 2024
@matthiaskrgr matthiaskrgr added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. labels Apr 17, 2024
@Luk-ESC
Copy link
Contributor

Luk-ESC commented Apr 17, 2024

Hit this while minimizing #123955 using the same rustc flags

pub fn run() {
    _ = factory();
}

trait Trait {}

fn factory() -> Box<dyn Trait> {
    loop { }
}

@nikic nikic added the requires-nightly This issue requires a nightly compiler in some way. label Apr 17, 2024
@Nilstrieb Nilstrieb changed the title llvm error: Do not know how to promote this operator virtual function elimination: llvm error: Do not know how to promote this operator Apr 18, 2024
@Nilstrieb Nilstrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

5 participants