Skip to content

[clang] Miscompile at O3 with SIGKILL #116553

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

Closed
cardigan1008 opened this issue Nov 17, 2024 · 1 comment · Fixed by #116627
Closed

[clang] Miscompile at O3 with SIGKILL #116553

cardigan1008 opened this issue Nov 17, 2024 · 1 comment · Fixed by #116627
Assignees
Labels

Comments

@cardigan1008
Copy link

When I compiled this code with O3, it triggered SIGKILL. With O0/1/2, it returned 0.

Bisected to 5b92713, which was committed by @fhahn

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

Code:

int printf(const char *, ...);
int a, c, d;
int *b;
char e;
short f;
int g(int i) {
  if (i <= 0)
    return 1;
  int h = 0;
  for (; h < i - 1; h++) {
    for (; d - h - 1;)
      if (c)
        b[d] = e = 1;
    if (e)
      break;
  }
  return 0;
}
void j() { g(f); }
int main(int i, char *k[]) {
  j();
  while (0 < f)
    ;
  printf("%X\n", a);
}
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 17, 2024
@EugeneZelenko EugeneZelenko added confirmed Verified by a second party llvm:transforms and removed clang Clang issues not falling into any other category labels Nov 18, 2024
@dtcxzyw dtcxzyw self-assigned this Nov 18, 2024
@dtcxzyw
Copy link
Member

dtcxzyw commented Nov 18, 2024

Reproducer: https://alive2.llvm.org/ce/z/fLN5gw

; bin/opt -passes=constraint-elimination test.ll -S
define i1 @test(i16 %n) {
entry:
  %cond = icmp slt i16 %n, 1
  br i1 %cond, label %exit, label %loop.preheader

loop.preheader:
  %sub = add nsw i16 %n, -1
  %ext = zext nneg i16 %sub to i32
  br label %loop

loop:
  %indvar = phi i32 [ %indvar.inc, %loop.latch ], [ 0, %loop.preheader ]
  %12 = icmp eq i32 %indvar, %ext
  br i1 %12, label %exit, label %loop.latch

loop.latch:
  %indvar.inc = add nuw nsw i32 %indvar, 1
  br label %loop

exit:
  %cmp = icmp sgt i16 %n, 0
  ret i1 %cmp
}

I will post a fix later.

dtcxzyw added a commit that referenced this issue Nov 18, 2024
…conditions (#116627)

This patch bails out non-dedicated exits to avoid adding exiting
conditions to invalid context.
Closes #116553.
tru pushed a commit to llvmbot/llvm-project that referenced this issue Nov 25, 2024
…conditions (llvm#116627)

This patch bails out non-dedicated exits to avoid adding exiting
conditions to invalid context.
Closes llvm#116553.

(cherry picked from commit 52361d0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants