asm goto wrong output at -O0 · Issue #110251 · llvm/llvm-project (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@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