Skip to content

“error: invalid operand for inline asm constraint 'i'” with enum members #42974

Closed

Description

@Ekleog

Hello,

It looks like in some cases (ie. not enough optimizations turned on), enum members cannot be used as 'i' operands for inline assembly:

#![feature(asm)]

#[repr(usize)]
enum Foo {
    Bar = 1,
}

fn main() {
    unsafe {
        asm!("" :: "i" (9isize), "i" (Foo::Bar));
    }
}

http://play.integer32.com/?gist=befc6872b583ffaa1609f081b7536b50&version=nightly

Given this is (with macros, maybe?) the only use I can think of 'i' operands, I think it is reasonable to say the 'i' operand is currently broken.

This would be solved by even the slightest level of constant folding, so I think even in debug mode it should actually constant fold to something that builds, and not have successful compilation be dependent of the specific compiler version and flags used (as is currently the case).

Activity

  1. parched commented on Jun 30, 2017

    @parched
    Contributor

    Same underlying issue as #41337 I guess.

  2. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Oct 25, 2019
  3. eddyb commented on Mar 13, 2020

    @eddyb
    Contributor

    Fix might be easy, see #41337 (comment).

  4. Amanieu commented on May 22, 2020

    @Amanieu
    Member

    This issue does not apply to the new asm! (RFC 2850) which has stricter checks on the types that can be used as asm operands.

    The legacy llvm_asm! is deprecated and is no longer maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions