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

Invalid code generated by Powerpc64 -O1, -Oz #74915

Open
godjhh opened this issue Dec 9, 2023 · 6 comments · May be fixed by #84419
Open

Invalid code generated by Powerpc64 -O1, -Oz #74915

godjhh opened this issue Dec 9, 2023 · 6 comments · May be fixed by #84419

Comments

@godjhh
Copy link

godjhh commented Dec 9, 2023

Proof of Concepts

#include <stdint.h>
#include <stdio.h>
struct {
  signed a;
} b = {-1L};
int32_t c;
uint64_t d;
uint8_t e[];
int32_t **h(int32_t **, int64_t);
static int32_t **f(uint32_t, int16_t);
int64_t g() {
  int32_t *k = &b;
  h(f((*k < 1) == *k, *k), *k);
}
int32_t **h(int32_t **, int64_t i) { d = i > 0 ^ i; }
int32_t **f(uint32_t l, int16_t j) {
  if (j || (e[0] = 0), c || l | -1L <= j)
    ;
  else
    for (;;)
      ;
}
int main() {
  g();
  printf("%lu\n", d);
  return 0;
}

godbolt link: https://www.godbolt.org/z/9xKG5Tac6

@dtcxzyw
Copy link
Member

dtcxzyw commented Dec 9, 2023

Could you please clarify your issue? Is it a miscompilation?

@dtcxzyw dtcxzyw added incomplete Issue not complete (e.g. missing a reproducer, build arguments, etc.) and removed new issue labels Dec 9, 2023
@godjhh
Copy link
Author

godjhh commented Dec 11, 2023

Could you please clarify your issue? Is it a miscompilation?

Invalid value output from optimization level -O1, -Oz.

Normal output(O0, O2, O3, Os): 18446744073709551615
Abnormal output(O1, Oz): 18446744073709551614

@dtcxzyw dtcxzyw added miscompilation llvm:optimizations backend:PowerPC and removed incomplete Issue not complete (e.g. missing a reproducer, build arguments, etc.) llvm:optimizations labels Dec 11, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 11, 2023

@llvm/issue-subscribers-backend-powerpc

Author: godjhh (godjhh)

### Proof of Concepts ``` #include <stdint.h> #include <stdio.h> struct { signed a; } b = {-1L}; int32_t c; uint64_t d; uint8_t e[]; int32_t **h(int32_t **, int64_t); static int32_t **f(uint32_t, int16_t); int64_t g() { int32_t *k = &b; h(f((*k < 1) == *k, *k), *k); } int32_t **h(int32_t **, int64_t i) { d = i > 0 ^ i; } int32_t **f(uint32_t l, int16_t j) { if (j || (e[0] = 0), c || l | -1L <= j) ; else for (;;) ; } int main() { g(); printf("%lu\n", d); return 0; } ```

godbolt link: https://www.godbolt.org/z/9xKG5Tac6

@nemanjai
Copy link
Member

This seems like some kind of generated test case. Have you confirmed that it is free from UB? Also can you comment on what code/project this affects?

@chenzheng1030
Copy link
Collaborator

This seems like some kind of generated test case. Have you confirmed that it is free from UB?

Verified with -fsanitize=address and -fsanitize=undefined, the case is OK.

The issue can be reproduced on AIX 64 with -mcpu=pwr8 or above. It is OK with -mcpu=pwr7.

@chenzheng1030
Copy link
Collaborator

Sorry for the late. I posted #84419 for this miscompile

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

Successfully merging a pull request may close this issue.

5 participants