Skip to content

asm goto wrong output at -O0 #110251

Closed
Closed
@fuhsnn

Description

@fuhsnn

Godbolt: https://godbolt.org/z/3a1vYMaoq

void asm_goto_output(int *arg) {
  asm goto (
    "  subl $11, %[value];"
    "  cmpl $11, %[value]; je %l[label];"
    : [value]"+r"(*arg)
    :
    : "cc"
    : label
    );
  label:
  return;
}

int main(void) {
  int i = 22;
  asm_goto_output(&i);
  return i;
}

The output should be 11, yet clang at -O0 stores 0 to the pointed-to variable.

Looks like only the jump branch is buggy, if input is changed to another value and the fall-through path is taken, the output is correct.

Possibily related: #74483

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions