Skip to content

[clang]Floating-point constant to unsigned integer error #109396

@bmq7911

Description

@bmq7911

When using clang (-O3) to convert a floating point constant such as -1234.56 into an unsigned integer and then printing out the converted result with printf, it produces a random value; whereas when using gcc(-O3) it outputs 0 instead.

#include <stdio.h>
int main(int argc, char * argv[]) {
    float x = -1234.56;
    unsigned int res = (unsigned int)x;
    printf("res: %u\n", res);
    return 0;
}

I have observed that when optimizing with -O3 flag, constant folding occurs during the EarlyCSE pass. However, during conversion within IEEEFloat module fails and results in oplnvalidOp which causes the conversion result to become poison. As a consequence of this poisoned parameter being passed through esi register according to x64 ABI standard rules , there exists an IMPLICIT_DEF statement assigning a value to rsi register which gets removed later on during processimpdefs pass leading ultimately leads producing random values being printed by printf function call . Do you know if there are any solutions available for this issue?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions