Repository navigation
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I may have found a bug in the compiler.
Source
The entirety of the code to reproduce this bug is this:
fn main() {
let callbacks = Callbacks::new();
callbacks.type_error(|x| &x.field);
}
pub struct Callbacks {
field: Vec<Box<Fn(&u8)>>,
}
impl Callbacks {
pub fn new() -> Callbacks {
Callbacks { field: Vec::new() }
}
pub fn no_type_error(&self, _selector: fn(&Callbacks) -> &Vec<Box<Fn(&u8)>>) {}
pub fn type_error<T>(&self, _selector: fn(&Callbacks) -> &Vec<Box<Fn(T)>>) {}
}Expected behavior
The program should build successfully, assuming the rustc type checker does not detect any errors at the level of the Rust type system.
Actual behavior
The rustc type checker seems happy with the program. However, presumably after the LLVM IR generation phase, and during some IR verification phase, I get this type error:
Compiling some_program_name v0.1.0 (SomePath\some_program_name)
Function return type does not match operand type of return inst!
ret %"alloc::vec::Vec<alloc::boxed::Box<core::ops::function::Fn<(&u8), Output=()>>>.0"* %6, !dbg !84
%"alloc::vec::Vec<alloc::boxed::Box<core::ops::function::Fn<(&u8), Output=()>>>"*LLVM ERROR: Broken function found, compilation aborted!
error: Could not compile `some_program_name`.Reacted by Vassalware, Nikita Popov and Konstantinos Gkinis
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Activity
[-]Rust compiler seems to generate invalid IR[/-][+]rustc seemingly generates invalid IR[/+]Centril commentedon Nov 19, 2018
Reduced:
arielb1 commentedon Nov 27, 2018
I thought we already fixed that by adding casts.
One possible fix that might be less harmful would be to give all types that are subtyping-equivalent the same LLVM type. They should be having the same layout anyway, and their fields should be subtyping-equivalent (because that's what subtyping-equivalence means).
The other option would be to insert casts when subtyping is taking place.
nikic commentedon Nov 30, 2018
This looks like a new instance of #47638.
cc @eddyb
eddyb commentedon Dec 1, 2018
#47638 was just an instance of the general problem, we just started generating named types for trait objects then, which made the problem show up in more cases.
I agree with @arielb1's first proposal, i.e. destroy the distinction ahead of time. We're only wasting time by inserting casts and LLVM wastes time ignoring those casts (insert rant about how counterproductive LLVM's types are).
arielb1 commentedon Feb 7, 2019
Reduced to its essence:
arielb1 commentedon Feb 16, 2019
An example that my previous approach will not make compile (but currently gives an ICE outputtypeparametermismatch):
arielb1 commentedon Feb 16, 2019
Nah you can do it without an
OutputTypeParameterMismatchICE, but you're still within deep ICE territoryarielb1 commentedon Feb 16, 2019
This is making me suspect, that when we get higher-ranked type bounds, finding a "canonical form for subtyping" will be impossible (note: don't be so sure. You can't? (shouldn't?) have higher-ranged type bounds in trait objects, so life might be better). Might as well insert casts.
Note that my old approach has problems with anonymization in invariant types:
7 remaining items
jackh726 commentedon Nov 30, 2022
Seems to be fixed since 1.23.
Add regression test for rust-lang#55976
JohnTitor commentedon Dec 14, 2022
Triage: The issue hasn't been fixed actually, at least on CI (CI stderr from #105691):
jackh726 commentedon Dec 14, 2022
That's interesting. It doesn't fail in a playground. Is this a debug assert now or something?
matthiaskrgr commentedon Dec 14, 2022
The build says
CI / PR (x86_64-gnu-llvm-13 ...so maybe this is fixed with nighty that uses llvm15.0.6but llvm 13 still causes problems?JohnTitor commentedon Dec 14, 2022
Likely, we could use
min-llvm-versionif so. Is there a CI builder that uses a newer LLVM on bors?compiler-errors commentedon Dec 14, 2022
Yeah, this is fixed by LLVM using its opaque pointers, so that's why it's possibly broken on LLVM 13?
Add regression test for rust-lang#55976
JohnTitor commentedon Dec 16, 2022
Re-submitted a PR with
min-llvm-version: #105785Rollup merge of rust-lang#105785 - JohnTitor:issue-55976-2, r=compile…
Auto merge of rust-lang#105820 - matthiaskrgr:rollup-uzm1l8f, r=matth…