Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscompilation on riscv64 when -fstruct-passing is used in CompCert 3.9 #412

Closed
monniaux opened this issue Sep 22, 2021 · 1 comment
Closed
Labels

Comments

@monniaux
Copy link
Contributor

#include <stdint.h>
#include <stdio.h>
static int32_t bk;
struct ba {
  int64_t bb;
};
static void dada(struct ba);
void nothing(void);
void stuff(void) {
  struct ba f = {5};
  int32_t i[1000];
  nothing();
  dada(f);
}
static void dada(struct ba k) {
  bk = k.bb;
}
void nothing(void) {
}
int main() {
  stuff();
  printf("result = %d\n", bk);
}
$ ccomp -fstruct-passing -interp source.c
result = 5
Time 53: observable event: extcall printf(& __stringlit_1,
             5) -> 11
Time 58: program terminated (exit code = 0)
$ ccomp -fstruct-passing source.c -o source
$ ./source
result = 0

The program compiles without warning (except for the unused variable i) with gcc, and also yields 5.

The same buggy result is obtained if ba is a union, not a structure.

@xavierleroy
Copy link
Contributor

Preliminary investigations by @bschommer suggest a wrong expansion of the __builtin_memcpy_aligned that is generated to implement struct passing. Stay tuned for a fix.

xavierleroy added a commit that referenced this issue Sep 23, 2021
In the "small" case, there was an error in the choice of temporary
registers to use when one argument is a stack locations.  The chosen
temporary could conflict with the other argument (the one that is a
register).

Fixes: #412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants