Skip to content

[clang++] Compiler producing wrong code/discarding code. #83746

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
Rugau opened this issue Mar 3, 2024 · 2 comments
Closed

[clang++] Compiler producing wrong code/discarding code. #83746

Rugau opened this issue Mar 3, 2024 · 2 comments
Labels
duplicate Resolved as duplicate invalid Resolved as invalid, i.e. not a bug undefined behaviour

Comments

@Rugau
Copy link

Rugau commented Mar 3, 2024

I accidentally found this bug that seems to be present in clang++ >= 13.0.0

#include <stdio.h>

int main(int argc, char** argv)
{
    if (argc * 2 > 999)
      printf("WTF?"); 

    while(1);
}
main:                                   # @main
        push    rax
        lea     rdi, [rip + .L.str]
        xor     eax, eax
        call    printf@PLT
.L.str:
        .asciz  "WTF?"

The compiler removed the if condition above, and considered it to be always true.

This is only present in the C++ compiler, in the C compiler it is producing the correct code.

In GCC and MSVC compilers, this does not happen and produces the correct code.

Is this right?
(and by the way, where is while(1)? -- the compiler removed it too? 🤣 )

https://godbolt.org/z/5MWEKrKjz

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Mar 3, 2024
@DimitryAndric
Copy link
Collaborator

Remove the while(1);. The program's behavior is undefined otherwise. You should also return a value from main().

@DimitryAndric DimitryAndric closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2024
@asl asl added the invalid Resolved as invalid, i.e. not a bug label Mar 4, 2024
@EugeneZelenko EugeneZelenko removed the clang Clang issues not falling into any other category label Mar 4, 2024
@shafik
Copy link
Collaborator

shafik commented Mar 4, 2024

Duplicate of: #66307

@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Resolved as duplicate invalid Resolved as invalid, i.e. not a bug undefined behaviour
Projects
None yet
Development

No branches or pull requests

5 participants