Skip to content

Returning an enum in 32-bit FFI is broken #10308

Closed
@alexcrichton

Description

@alexcrichton

Here's the output of a shell session on 32-bit linux which causes the failure.

[~/rust[uv-rewrite]] $ cat foo.c 
enum A {                                                                                                            
  B, C                                                                                                              
};                                                                                                                  

enum A foo() { return B; }                                                                                          
[~/rust[uv-rewrite]] $ gcc -m32 foo.c -c -o foo.o  
[~/rust[uv-rewrite]] $ ar rcs libfoo.a foo.o    
[~/rust[uv-rewrite]] $ cat foo.rs    
#[allow(cstack)];                                                                                                   

#[repr(C)]                                                                                                          
enum A {                                                                                                            
  B, C                                                                                                              
}                                                                                                                   

#[link_args = "-lfoo"]                                                                                              
extern {                                                                                                            
  fn foo() -> A;                                                                                                    
}                                                                                                                   

fn main() {                                                                                                         
  unsafe { foo(); }                                                                                                 
}                                                                                                                   
[~/rust[uv-rewrite]] $ ./i686-unknown-linux-gnu/stage2/bin/rustc foo.rs 
[~/rust[uv-rewrite]] $ ./foo   
zsh: segmentation fault (core dumped)  ./foo                                                                        

cc @jld

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions