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

wrong code at -Os and above on x86_64-linux-gnu #56410

Closed
zhendongsu opened this issue Jul 6, 2022 · 4 comments
Closed

wrong code at -Os and above on x86_64-linux-gnu #56410

zhendongsu opened this issue Jul 6, 2022 · 4 comments

Comments

@zhendongsu
Copy link

zhendongsu commented Jul 6, 2022

It appears to be a recent regression from 14.0.0.

% clangtk -v
clang version 15.0.0 (https://github.com/llvm/llvm-project.git b9513a70e16a7b7141601e09d5b9fc1cdecb26ab)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
% 
% clangtk -O1 -w small.c; ./a.out
% 
% clangtk -Os -w small.c
% ./a.out
Segmentation fault
% 
% cat small.c
int printf(const char *, ...);
int a, h, b, d, f, i, j = -1, *c, *e, *g;
int main() {
  char *k, *l;
  for (; h < 8; h++) {
    int m = i;
    for (; a < 8; a++)
      if (d)
        printf(k);
    i = 71;
    k = (char *)&m;
    c = (int *)&l;
  }
  while (1) {
    int o = b, n = 7 & a;
    if (b && f) {
      printf("0");
      g = &o;
      for (; *k; (*k)++)
        ;
    }
    if (n)
      continue;
    int q = ~o, p = a ^ o;
    unsigned char r = ~(~(j * p) * o * ~(q ^ a));
    if (r < 8)
      break;
    return 0;
  }
  *e = 0;
  return 0;
}

Compiler Explorer: https://godbolt.org/z/a4Y3M51qP

@fhahn

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 6, 2022

@llvm/issue-subscribers-backend-x86

@fhahn
Copy link
Contributor

fhahn commented Jul 6, 2022

This also reproduces on ARM64. Bisecting now

@fhahn
Copy link
Contributor

fhahn commented Jul 8, 2022

It looks like this is a mis-compile with opaque pointers and that's why it doesn't reproduce with 14.0

It also fails on 14.0 with clang -Os -w -mllvm -opaque-pointers https://godbolt.org/z/1v3frYjE6

@nikic
Copy link
Contributor

nikic commented Jul 12, 2022

This is the same issue as #51838 (and works fine with -mllvm -no-stack-coloring). Opaque pointers are relevant in that they make the problematic accesses promotable.

@nikic nikic closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2022
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants