https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109581

            Bug ID: 109581
           Summary: Comparing with -HUGE_VAL wrong result
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daschuer at mixxx dot org
  Target Milestone: ---

Comparing with -HUGE_VAL gives the wrong result with gcc (GCC) 13.0.1 20230401
(Red Hat 13.0.1-0).

GCC 12.2 is and clang are not effected. 

This bug breaks Mixxx after compiling it on openSUSE Tumbleweed and Fedora 38 
https://github.com/mixxxdj/mixxx/issues/11483

The workaround is to store -HUGE_VAL as a volatile first. 

This is a minimal code that demonstrates the issue: 

#include <stdio.h>
#include <math.h>

int main(int num) {
    long long rawInf = 0xfff0000000000000;
    volatile  double inf = *(double*)(void*)&rawInf;

    if (inf == -HUGE_VAL) {
        puts("Success");
    } else {
        puts("Error");
    }

    return 0;
}


The following flags are used: 
-g -pipe -O3 -ffast-math -funroll-loops -fomit-frame-pointer -mtune=generic
-Wall -Wextra -Wfloat-conversion -Werror=return-type


Result 
GCC 12.2 and lower "Success"
GCC 13.0 "Error"

Details: https://godbolt.org/z/7bnb77hv4

Reply via email to