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

Named labels in asm!() blocks cause crashes on Mac OSX #16378

Closed
DaGenix opened this issue Aug 9, 2014 · 17 comments
Closed

Named labels in asm!() blocks cause crashes on Mac OSX #16378

DaGenix opened this issue Aug 9, 2014 · 17 comments
Labels
A-inline-assembly Area: inline asm!(..) C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-macos Operating system: macOS requires-nightly This issue requires a nightly compiler in some way.

Comments

@DaGenix
Copy link

DaGenix commented Aug 9, 2014

The following code crashes on Mac OSX:

#![feature(asm)]

fn main() {
    unsafe {
        asm!(" test:") 
    }
}
@sinistersnare
Copy link
Contributor

On http://play.rust-lang.org this does not crash. link

@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

I think the crash only happens on Max OSX. I believe that play.rust-lang.org runs on Linux. I've used asm!() with named labels on Linux without any issues.

@sinistersnare
Copy link
Contributor

I figure, I just wanted to point it out :)

@huonw
Copy link
Member

huonw commented Aug 9, 2014

Does the code crash at runtime or is it crashing the compiler? (What's the crash behaviour? A segfault?)

@huonw huonw added the A-mac-osx label Aug 9, 2014
@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

It compiles fine, but crashes when its run with:

Segmentation fault: 11

@huonw
Copy link
Member

huonw commented Aug 9, 2014

What's the output of rustc --emit=asm look like? (creates a .s file)

@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

Here is test2.s:

    .section    __TEXT,__text,regular,pure_instructions
    .section    __DWARF,__debug_info,regular,debug
Lsection_info:
    .section    __DWARF,__debug_abbrev,regular,debug
Lsection_abbrev:
    .section    __DWARF,__debug_line,regular,debug
Lsection_line:
    .section    __DWARF,__debug_str,regular,debug
Linfo_string:
    .section    __DWARF,__debug_loc,regular,debug
Lsection_debug_loc:
    .section    __DWARF,__debug_ranges,regular,debug
Ldebug_range:
    .section    __TEXT,__text,regular,pure_instructions
    .align  4, 0x90
__ZN4main20h8b95006aaacf56a1eaaE:
Lfunc_begin0:
    .file   1 "test2.rs"
    .loc    1 3 0
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB0_0
    movabsq $8, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB0_0:
    pushq   %rbp
Ltmp0:
    .cfi_def_cfa_offset 16
Ltmp1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp2:
    .cfi_def_cfa_register %rbp
    .loc    1 5 0 prologue_end
Ltmp3:
    ## InlineAsm Start
test:
    ## InlineAsm End
    popq    %rbp
    retq
Ltmp4:
Lfunc_end0:
    .cfi_endproc

    .globl  _main
    .align  4, 0x90
_main:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB1_0
    movabsq $24, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB1_0:
    pushq   %rbp
Ltmp5:
    .cfi_def_cfa_offset 16
Ltmp6:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp7:
    .cfi_def_cfa_register %rbp
    subq    $16, %rsp
    leaq    __ZN4main20h8b95006aaacf56a1eaaE(%rip), %rax
    movq    %rdi, -8(%rbp)
    movq    %rax, %rdi
    movq    -8(%rbp), %rax
    movq    %rsi, -16(%rbp)
    movq    %rax, %rsi
    movq    -16(%rbp), %rdx
    callq   __ZN10lang_start20h3eb2912460ad7fe8BueE
    addq    $16, %rsp
    popq    %rbp
    retq
    .cfi_endproc

Ldebug_end0:
    .section    __DWARF,__debug_str,regular,debug
Linfo_string0:
    .asciz  "rustc version 0.12.0-pre-nightly (a1429bca5 2014-08-08 21:36:11 +0000)"
Linfo_string1:
    .asciz  "./test2.rs"
Linfo_string2:
    .asciz  "/Users/enix/code/rusttest"
Linfo_string3:
    .asciz  "test2"
Linfo_string4:
    .asciz  "main"
Linfo_string5:
    .asciz  "_ZN5test24mainE"
    .section    __DWARF,__debug_info,regular,debug
L__DWARF__debug_info_begin0:
    .long   75
    .short  2
Lset0 = Lsection_abbrev-Lsection_abbrev
    .long   Lset0
    .byte   8
    .byte   1
Lset1 = Linfo_string0-Linfo_string
    .long   Lset1
    .short  36864
Lset2 = Linfo_string1-Linfo_string
    .long   Lset2
Lset3 = Lline_table_start0-Lsection_line
    .long   Lset3
Lset4 = Linfo_string2-Linfo_string
    .long   Lset4
    .quad   Lfunc_begin0
Lset5 = Lfunc_end0-Lfunc_begin0
    .long   Lset5
    .byte   2
Lset6 = Linfo_string3-Linfo_string
    .long   Lset6
    .byte   3
    .quad   Lfunc_begin0
    .quad   Lfunc_end0
    .byte   1
    .byte   86
Lset7 = Linfo_string5-Linfo_string
    .long   Lset7
Lset8 = Linfo_string4-Linfo_string
    .long   Lset8
    .byte   1
    .byte   3
    .byte   1
    .byte   0
    .byte   0
L__DWARF__debug_info_end0:
    .section    __DWARF,__debug_abbrev,regular,debug
    .byte   1
    .byte   17
    .byte   1
    .byte   37
    .byte   14
    .byte   19
    .byte   5
    .byte   3
    .byte   14
    .byte   16
    .byte   6
    .byte   27
    .byte   14
    .byte   17
    .byte   1
    .byte   18
    .byte   6
    .byte   0
    .byte   0
    .byte   2
    .byte   57
    .byte   1
    .byte   3
    .byte   14
    .byte   0
    .byte   0
    .byte   3
    .byte   46
    .byte   0
    .byte   17
    .byte   1
    .byte   18
    .byte   1
    .byte   64
    .byte   10
    .ascii  "\207@"
    .byte   14
    .byte   3
    .byte   14
    .byte   58
    .byte   11
    .byte   59
    .byte   11
    .byte   50
    .byte   11
    .byte   0
    .byte   0
    .byte   0
    .section    __DWARF,__debug_ranges,regular,debug
    .section    __DWARF,__debug_loc,regular,debug
    .section    __DWARF,__apple_names,regular,debug
Lnames_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   2
    .long   2
    .long   12
    .long   0
    .long   1
    .short  1
    .short  6
    .long   0
    .long   1
    .long   2090499946
    .long   1217565201
    .long   LNames0-Lnames_begin
    .long   LNames1-Lnames_begin
LNames0:
Lset9 = Linfo_string4-Linfo_string
    .long   Lset9
    .long   1
    .long   47
    .long   0
LNames1:
Lset10 = Linfo_string5-Linfo_string
    .long   Lset10
    .long   1
    .long   47
    .long   0
    .section    __DWARF,__apple_objc,regular,debug
Lobjc_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   1
    .long   0
    .long   12
    .long   0
    .long   1
    .short  1
    .short  6
    .long   -1
    .section    __DWARF,__apple_namespac,regular,debug
Lnamespac_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   1
    .long   1
    .long   12
    .long   0
    .long   1
    .short  1
    .short  6
    .long   0
    .long   275477815
    .long   Lnamespac0-Lnamespac_begin
Lnamespac0:
Lset11 = Linfo_string3-Linfo_string
    .long   Lset11
    .long   1
    .long   42
    .long   0
    .section    __DWARF,__apple_types,regular,debug
Ltypes_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   1
    .long   0
    .long   20
    .long   0
    .long   3
    .short  1
    .short  6
    .short  3
    .short  5
    .short  4
    .short  11
    .long   -1

.subsections_via_symbols
    .section    __DWARF,__debug_line,regular,debug
Lline_table_start0:

@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

At a quick glance, I don't see anything obviously wrong, so, I don't really know whats happening.

As a note, the crashes occur with and without debugging information (-g) and without and without optimization (-O).

@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

As another note, the following compiles and runs file:

#![feature(asm)]

fn main() {
    unsafe {
        asm!("") 
    }
}

It compiles down to:

    .section    __TEXT,__text,regular,pure_instructions
    .section    __DWARF,__debug_info,regular,debug
Lsection_info:
    .section    __DWARF,__debug_abbrev,regular,debug
Lsection_abbrev:
    .section    __DWARF,__debug_line,regular,debug
Lsection_line:
    .section    __DWARF,__debug_str,regular,debug
Linfo_string:
    .section    __DWARF,__debug_loc,regular,debug
Lsection_debug_loc:
    .section    __DWARF,__debug_ranges,regular,debug
Ldebug_range:
    .section    __TEXT,__text,regular,pure_instructions
    .align  4, 0x90
__ZN4main20h503ced65c10fa3edeaaE:
Lfunc_begin0:
    .file   1 "test3.rs"
    .loc    1 3 0
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB0_0
    movabsq $8, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB0_0:
    pushq   %rbp
Ltmp0:
    .cfi_def_cfa_offset 16
Ltmp1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp2:
    .cfi_def_cfa_register %rbp
    .loc    1 5 0 prologue_end
Ltmp3:
    ## InlineAsm Start
    ## InlineAsm End
    popq    %rbp
    retq
Ltmp4:
Lfunc_end0:
    .cfi_endproc

    .globl  _main
    .align  4, 0x90
_main:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB1_0
    movabsq $24, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB1_0:
    pushq   %rbp
Ltmp5:
    .cfi_def_cfa_offset 16
Ltmp6:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp7:
    .cfi_def_cfa_register %rbp
    subq    $16, %rsp
    leaq    __ZN4main20h503ced65c10fa3edeaaE(%rip), %rax
    movq    %rdi, -8(%rbp)
    movq    %rax, %rdi
    movq    -8(%rbp), %rax
    movq    %rsi, -16(%rbp)
    movq    %rax, %rsi
    movq    -16(%rbp), %rdx
    callq   __ZN10lang_start20h3eb2912460ad7fe8BueE
    addq    $16, %rsp
    popq    %rbp
    retq
    .cfi_endproc

Ldebug_end0:
    .section    __DWARF,__debug_str,regular,debug
Linfo_string0:
    .asciz  "rustc version 0.12.0-pre-nightly (a1429bca5 2014-08-08 21:36:11 +0000)"
Linfo_string1:
    .asciz  "./test3.rs"
Linfo_string2:
    .asciz  "/Users/enix/code/rusttest"
Linfo_string3:
    .asciz  "test3"
Linfo_string4:
    .asciz  "main"
Linfo_string5:
    .asciz  "_ZN5test34mainE"
    .section    __DWARF,__debug_info,regular,debug
L__DWARF__debug_info_begin0:
    .long   75
    .short  2
Lset0 = Lsection_abbrev-Lsection_abbrev
    .long   Lset0
    .byte   8
    .byte   1
Lset1 = Linfo_string0-Linfo_string
    .long   Lset1
    .short  36864
Lset2 = Linfo_string1-Linfo_string
    .long   Lset2
Lset3 = Lline_table_start0-Lsection_line
    .long   Lset3
Lset4 = Linfo_string2-Linfo_string
    .long   Lset4
    .quad   Lfunc_begin0
Lset5 = Lfunc_end0-Lfunc_begin0
    .long   Lset5
    .byte   2
Lset6 = Linfo_string3-Linfo_string
    .long   Lset6
    .byte   3
    .quad   Lfunc_begin0
    .quad   Lfunc_end0
    .byte   1
    .byte   86
Lset7 = Linfo_string5-Linfo_string
    .long   Lset7
Lset8 = Linfo_string4-Linfo_string
    .long   Lset8
    .byte   1
    .byte   3
    .byte   1
    .byte   0
    .byte   0
L__DWARF__debug_info_end0:
    .section    __DWARF,__debug_abbrev,regular,debug
    .byte   1
    .byte   17
    .byte   1
    .byte   37
    .byte   14
    .byte   19
    .byte   5
    .byte   3
    .byte   14
    .byte   16
    .byte   6
    .byte   27
    .byte   14
    .byte   17
    .byte   1
    .byte   18
    .byte   6
    .byte   0
    .byte   0
    .byte   2
    .byte   57
    .byte   1
    .byte   3
    .byte   14
    .byte   0
    .byte   0
    .byte   3
    .byte   46
    .byte   0
    .byte   17
    .byte   1
    .byte   18
    .byte   1
    .byte   64
    .byte   10
    .ascii  "\207@"
    .byte   14
    .byte   3
    .byte   14
    .byte   58
    .byte   11
    .byte   59
    .byte   11
    .byte   50
    .byte   11
    .byte   0
    .byte   0
    .byte   0
    .section    __DWARF,__debug_ranges,regular,debug
    .section    __DWARF,__debug_loc,regular,debug
    .section    __DWARF,__apple_names,regular,debug
Lnames_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   2
    .long   2
    .long   12
    .long   0
    .long   1
    .short  1
    .short  6
    .long   0
    .long   -1
    .long   2090499946
    .long   -1785934126
    .long   LNames0-Lnames_begin
    .long   LNames1-Lnames_begin
LNames0:
Lset9 = Linfo_string4-Linfo_string
    .long   Lset9
    .long   1
    .long   47
    .long   0
LNames1:
Lset10 = Linfo_string5-Linfo_string
    .long   Lset10
    .long   1
    .long   47
    .long   0
    .section    __DWARF,__apple_objc,regular,debug
Lobjc_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   1
    .long   0
    .long   12
    .long   0
    .long   1
    .short  1
    .short  6
    .long   -1
    .section    __DWARF,__apple_namespac,regular,debug
Lnamespac_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   1
    .long   1
    .long   12
    .long   0
    .long   1
    .short  1
    .short  6
    .long   0
    .long   275477816
    .long   Lnamespac0-Lnamespac_begin
Lnamespac0:
Lset11 = Linfo_string3-Linfo_string
    .long   Lset11
    .long   1
    .long   42
    .long   0
    .section    __DWARF,__apple_types,regular,debug
Ltypes_begin:
    .long   1212240712
    .short  1
    .short  0
    .long   1
    .long   0
    .long   20
    .long   0
    .long   3
    .short  1
    .short  6
    .short  3
    .short  5
    .short  4
    .short  11
    .long   -1

.subsections_via_symbols
    .section    __DWARF,__debug_line,regular,debug
Lline_table_start0:

Diffing the two, I get:

(test2.s is the program that crashes, test3.s is the one that doesn't)

--- test2.s 2014-08-09 02:17:59.000000000 -0400
+++ test3.s 2014-08-09 02:23:10.000000000 -0400
@@ -13,9 +13,9 @@
 Ldebug_range:
    .section    __TEXT,__text,regular,pure_instructions
    .align  4, 0x90
-__ZN4main20h8b95006aaacf56a1eaaE:
+__ZN4main20h503ced65c10fa3edeaaE:
 Lfunc_begin0:
-   .file   1 "test2.rs"
+   .file   1 "test3.rs"
    .loc    1 3 0
    .cfi_startproc
    cmpq    %gs:816, %rsp
@@ -36,7 +36,6 @@
    .loc    1 5 0 prologue_end
 Ltmp3:
    ## InlineAsm Start
-test:
    ## InlineAsm End
    popq    %rbp
    retq
@@ -64,7 +63,7 @@
 Ltmp7:
    .cfi_def_cfa_register %rbp
    subq    $16, %rsp
-   leaq    __ZN4main20h8b95006aaacf56a1eaaE(%rip), %rax
+   leaq    __ZN4main20h503ced65c10fa3edeaaE(%rip), %rax
    movq    %rdi, -8(%rbp)
    movq    %rax, %rdi
    movq    -8(%rbp), %rax
@@ -82,15 +81,15 @@
 Linfo_string0:
    .asciz  "rustc version 0.12.0-pre-nightly (a1429bca5 2014-08-08 21:36:11 +0000)"
 Linfo_string1:
-   .asciz  "./test2.rs"
+   .asciz  "./test3.rs"
 Linfo_string2:
    .asciz  "/Users/enix/code/rusttest"
 Linfo_string3:
-   .asciz  "test2"
+   .asciz  "test3"
 Linfo_string4:
    .asciz  "main"
 Linfo_string5:
-   .asciz  "_ZN5test24mainE"
+   .asciz  "_ZN5test34mainE"
    .section    __DWARF,__debug_info,regular,debug
 L__DWARF__debug_info_begin0:
    .long   75
@@ -193,9 +192,9 @@
    .short  1
    .short  6
    .long   0
-   .long   1
+   .long   -1
    .long   2090499946
-   .long   1217565201
+   .long   -1785934126
    .long   LNames0-Lnames_begin
    .long   LNames1-Lnames_begin
 LNames0:
@@ -236,7 +235,7 @@
    .short  1
    .short  6
    .long   0
-   .long   275477815
+   .long   275477816
    .long   Lnamespac0-Lnamespac_begin
 Lnamespac0:
 Lset11 = Linfo_string3-Linfo_string

@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

Oh, as another note, both of those assembly files were the result of compiling with -g and without any optimization.

@huonw
Copy link
Member

huonw commented Aug 9, 2014

The output would likely be shorter and far easier to digest without -g.

@DaGenix
Copy link
Author

DaGenix commented Aug 9, 2014

the program that crashes (with -O and no -g):

    .section    __TEXT,__text,regular,pure_instructions
    .align  4, 0x90
__ZN4main20h8b95006aaacf56a1eaaE:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB0_2
    movabsq $8, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB0_2:
    pushq   %rbp
Ltmp0:
    .cfi_def_cfa_offset 16
Ltmp1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp2:
    .cfi_def_cfa_register %rbp
    ## InlineAsm Start
test:
    ## InlineAsm End
    popq    %rbp
    retq
    .cfi_endproc

    .globl  _main
    .align  4, 0x90
_main:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB1_2
    movabsq $8, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB1_2:
    pushq   %rbp
Ltmp3:
    .cfi_def_cfa_offset 16
Ltmp4:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp5:
    .cfi_def_cfa_register %rbp
    movq    %rsi, %rax
    movq    %rdi, %rcx
    leaq    __ZN4main20h8b95006aaacf56a1eaaE(%rip), %rdi
    movq    %rcx, %rsi
    movq    %rax, %rdx
    popq    %rbp
    jmp __ZN10lang_start20h3eb2912460ad7fe8BueE
    .cfi_endproc


.subsections_via_symbols

And the 2nd program that doesn't:

    .section    __TEXT,__text,regular,pure_instructions
    .align  4, 0x90
__ZN4main20h503ced65c10fa3edeaaE:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB0_2
    movabsq $8, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB0_2:
    pushq   %rbp
Ltmp0:
    .cfi_def_cfa_offset 16
Ltmp1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp2:
    .cfi_def_cfa_register %rbp
    ## InlineAsm Start
    ## InlineAsm End
    popq    %rbp
    retq
    .cfi_endproc

    .globl  _main
    .align  4, 0x90
_main:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB1_2
    movabsq $8, %r10
    movabsq $0, %r11
    callq   ___morestack
    retq
LBB1_2:
    pushq   %rbp
Ltmp3:
    .cfi_def_cfa_offset 16
Ltmp4:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp5:
    .cfi_def_cfa_register %rbp
    movq    %rsi, %rax
    movq    %rdi, %rcx
    leaq    __ZN4main20h503ced65c10fa3edeaaE(%rip), %rdi
    movq    %rcx, %rsi
    movq    %rax, %rdx
    popq    %rbp
    jmp __ZN10lang_start20h3eb2912460ad7fe8BueE
    .cfi_endproc


.subsections_via_symbols

and the diff:

--- test2.s 2014-08-09 02:30:46.000000000 -0400
+++ test3.s 2014-08-09 02:30:20.000000000 -0400
@@ -1,6 +1,6 @@
    .section    __TEXT,__text,regular,pure_instructions
    .align  4, 0x90
-__ZN4main20h8b95006aaacf56a1eaaE:
+__ZN4main20h503ced65c10fa3edeaaE:
    .cfi_startproc
    cmpq    %gs:816, %rsp
    ja  LBB0_2
@@ -18,7 +18,6 @@
 Ltmp2:
    .cfi_def_cfa_register %rbp
    ## InlineAsm Start
-test:
    ## InlineAsm End
    popq    %rbp
    retq
@@ -45,7 +44,7 @@
    .cfi_def_cfa_register %rbp
    movq    %rsi, %rax
    movq    %rdi, %rcx
-   leaq    __ZN4main20h8b95006aaacf56a1eaaE(%rip), %rdi
+   leaq    __ZN4main20h503ced65c10fa3edeaaE(%rip), %rdi
    movq    %rcx, %rsi
    movq    %rax, %rdx
    popq    %rbp

@steveklabnik
Copy link
Member

Triage: this ticket is quite old, but I don't have a mac to test to see if it reproduces today.

@mark-buer
Copy link
Contributor

Just tested it (using latest nightly installed via rustup).
Running the compiled program (from original post) crashes with:

Segmentation fault: 11

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. labels Jul 21, 2017
@etaoins
Copy link
Contributor

etaoins commented Jan 11, 2018

This still occurs with nightly. Interestingly, if the LLVM IR is compiled with an external llc/opt 5.0.1 it works fine:

> cat broken.rs
#![feature(asm)]

fn main() {
    unsafe {
        asm!(" test:")
    }
    println!("HERE")
}

> rustc broken.rs; and ./broken
fish: 'and ./broken' terminated by signal SIGSEGV (Address boundary error)

> opt -O2 broken.ll | llc -O2 -o broken.s; and clang build/x86_64-apple-darwin/stage2/lib/libstd-774948d0982f7640.dylib  broken.s  -o broken
> ./broken
HERE

@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 25, 2019
@stevecheckoway
Copy link

I gave an explanation of what's happening #63977 (comment)

@Amanieu
Copy link
Member

Amanieu commented May 23, 2020

You should only use local labels in inline assembly. This is stated in the documentation for the new asm! macro.

@Amanieu Amanieu closed this as completed May 23, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 21, 2024
fix: better handling of SelfParam in assist 'inline_call'

fix rust-lang#15470.

The current `inline_call` directly translates `&self` into `let ref this = ...;` and `&mut self` into `let ref mut this = ...;`. However, it does not handle some complex scenarios.

This PR addresses the following transformations (assuming the receiving object is `obj`):

- `self`: `let this = obj`
- `mut self`: `let mut this = obj`
- `&self`: `let this = &obj`
- `&mut self`
  + If `obj` is `let mut obj = ...`, use a mutable reference: `let this = &mut obj`
  + If `obj` is `let obj = &mut ...;`, perform a reborrow: `let this = &mut *obj`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-macos Operating system: macOS requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

10 participants