Skip to content

[RISCV] Miscompile at -O3 with zbb #85190

Closed
@dtcxzyw

Description

@dtcxzyw

Reduced test case:

#include <stdint.h>
#include <stdio.h>
int8_t d;
int32_t b;
uint64_t c;
int64_t safe_add_func_int64_t_s_s(int64_t si1, int64_t si2)
{
  return ((si1<0) && (si2<0) && (si1 < (INT64_MIN-si2))) ?
    (si1) :
    (si1 + si2);
}
int main() {
  do b = safe_add_func_int64_t_s_s(c, 7 | c);
  while (d);
  printf("%d\n", b);
  return 0;
}
> gcc -O0 test.c -fsanitize=undefined,address && ./a.out
7
> bin/clang -O3 -march=rv64gc_zbb test.c --target=riscv64-linux-gnu
> qemu-riscv64 -L /usr/riscv64-linux-gnu -cpu rv64,zbb=true ./a.out
0

LLVM version: eb21ee4
qemu version: v8.2.1

cc @topperc @asb

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