Skip to content

[RISCV] Miscompile with -O3 #87042

@dtcxzyw

Description

@dtcxzyw

Reduced test case:

#include <stdio.h>
#include <stdint.h>
int16_t g;
int32_t f;
uint32_t h;
uint64_t j = 6;
static uint64_t o(int16_t x, uint32_t *a, int16_t ac) {
  if (!x) j |= f;
  f = ac ? 7 % ac : 7;
  return j;
}
int main() {
  uint64_t v1 =  o(g, &h, 8);
  uint64_t v2 = o(v1, &h, 0);
  o(v2 >> 8, &h, 0);
  printf("%lu\n", j);
  return 0;
}
$ gcc -O0 -fsanitize=address,undefined test.c && ./a.out
7
$ bin/clang -O3 --target=riscv64-linux-gnu test.c
$ qemu-riscv64 -L /usr/riscv64-linux-gnu ./a.out
13

llvm version: ba6b2d2
qemu version: v8.2.0

Metadata

Metadata

Assignees

Labels

llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions