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

"a" is "b" is true #4556

Closed
FeepingCreature opened this issue Jan 8, 2024 · 2 comments
Closed

"a" is "b" is true #4556

FeepingCreature opened this issue Jan 8, 2024 · 2 comments

Comments

@FeepingCreature
Copy link
Contributor

Repro:

extern(C) void printf(const char*, ...);

void main()
{
    if ("a" is "b")
    {
        printf("oops.\n");
    }
}

The issue goes away if I switch to IRBuilder<llvm::NoFolder>. I suspect this is a side effect of strings being unnamed_addr, meaning LLVM not-entirely-unreasonably concludes "well, I can interpret icmp eq i8* @.str.1, @.str.2 however I feel like". Of course, "a" will never actually be merged with "b", but...

@JohanEngelen
Copy link
Member

JohanEngelen commented Jan 8, 2024

This bug is not related to LLVM or wrong optimization by LLVM. The generated code does not even contain an icmp because LDC recognizes that the condition is a compile-time constant and thus is known to be either true or false at compile-time and no branching is needed. (#3134, since 1.19)
The bug arises since 1.25, where for some reason "a" is "b" evaluates to true (when it is the condition of if).

Edit: Actually this is related to LLVM. The bug shows up since LLVM 11.0.1, not with 11.0.0. LDC 1.25 happens to be released with LLVM 11.0.1, LDC 1.24 with LLVM 11.0.0.

Reproducer for change of LLVM behavior: https://llvm.godbolt.org/z/T4G9jcs1e
Notice how 11.0.0 folds the icmp to false, but 11.0.1 does not constfold the if-condition at all.

@JohanEngelen
Copy link
Member

Related LLVM change: https://reviews.llvm.org/D87123

JohanEngelen added a commit to JohanEngelen/ldc that referenced this issue Jan 8, 2024
…ion expressions that are more complex than a simple integer.

Resolves issue ldc-developers#4556
JohanEngelen added a commit that referenced this issue Jan 10, 2024
#4559)

Fix if-statement elision on constant true/false condition, for condition expressions that are more complex than a simple integer.

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

No branches or pull requests

2 participants