Skip to content

Floating point comparison miscompilation #41

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
aykevl opened this issue Nov 12, 2020 · 2 comments
Closed

Floating point comparison miscompilation #41

aykevl opened this issue Nov 12, 2020 · 2 comments

Comments

@aykevl
Copy link

aykevl commented Nov 12, 2020

I have the following C code:

void sideeffect(void);

int identify(float v) {
    if (v+v == v && v > 0) {
        return 2;
    }
    if (v < 0) {
        sideeffect();
        return 5;
    }
    return 4;
}

When I call this with identify(20) (where 20 is the floating point value with bits 0x41a00000, see here) the function will return 5. This is clearly incorrect, as v is 20 which is bigger than 0. Note that sideeffect doesn't do anything, but without some external call the misbehavior appears to be optimized away.
I have seen the same issue with other positive integers, I don't think the actual number matters.

I found the issue originally in TinyGo (runtime.printfloat32) but managed to reduce it and convert it to C while still maintaining the incorrect behavior.

This issue might be a duplicate of #20.

@andreisfr
Copy link
Collaborator

Hi @aykevl ! This problem corrected in xtensa_release_11.0.0 branch, please check it

@aykevl
Copy link
Author

aykevl commented Dec 3, 2020

Thank you! I have tested this and it is indeed fixed with the LLVM 11 branch.

@aykevl aykevl closed this as completed Dec 3, 2020
aykevl added a commit to tinygo-org/tinygo that referenced this issue Dec 3, 2020
This allows working with float32 values, for example it allows
testdata/float.go to work correctly (assuming an Xtensa backend bug is
fixed, see espressif/llvm-project#41).
aykevl added a commit to tinygo-org/tinygo that referenced this issue Dec 10, 2020
This allows working with float32 values, for example it allows
testdata/float.go to work correctly (assuming an Xtensa backend bug is
fixed, see espressif/llvm-project#41).
deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue Dec 11, 2020
This allows working with float32 values, for example it allows
testdata/float.go to work correctly (assuming an Xtensa backend bug is
fixed, see espressif/llvm-project#41).
deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue Dec 11, 2020
This allows working with float32 values, for example it allows
testdata/float.go to work correctly (assuming an Xtensa backend bug is
fixed, see espressif/llvm-project#41).
premek pushed a commit to premek/tinygo that referenced this issue Dec 15, 2020
This allows working with float32 values, for example it allows
testdata/float.go to work correctly (assuming an Xtensa backend bug is
fixed, see espressif/llvm-project#41).
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