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

Incorrect transformation for loops by optimization passes #86498

Open
ararmine opened this issue Mar 25, 2024 · 0 comments
Open

Incorrect transformation for loops by optimization passes #86498

ararmine opened this issue Mar 25, 2024 · 0 comments

Comments

@ararmine
Copy link

ararmine commented Mar 25, 2024

When compiling the following example with clang -O3 opt level, the program does not print the expected output and the returned status is 48.
Steps to reproduce:

1. cat bug.cpp
#include <stdio.h>
#include <stdlib.h>

struct C {
  int i[100000000];
};

int main()
{
  // Eat all available chunks of memory that are big enough for
  // struct C so that the next allocation request will fail.
  while (malloc(sizeof(struct C)));
  printf("End\n");
  return 0;
}
2. clang++ bug.cpp -O3
3. ./a.out
4. echo $?
    48

This is the generated LLVM IR after the optimizations. The loop is optimized away and so is 'printf':

define dso_local noundef i32 @main() local_unnamed_addr #0 !dbg !267 {
  unreachable, !dbg !268
}

Compiling the same example with GCC, the program produces the expected output:

1. g++ bug.cpp -O3
2. ./a.out 
End
3. echo $?
    0
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

2 participants