Skip to content

floating point isnan might have issues #31

@ZERICO2005

Description

@ZERICO2005

Fine on -Oz, but breaks at -O0

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#if 1
#define test_printf printf
#else
#define test_printf(...)
#endif

#include "f32_fminmax_LUT.h"

#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))

typedef union F32_pun {
    float flt;
    uint32_t bin;
} F32_pun;

size_t run_test(void) {
    typedef struct { F32_pun x; F32_pun y; } input_t;
    typedef struct { F32_pun f_min; F32_pun f_max; } output_t;

    const size_t length = ARRAY_LENGTH(f32_fminmax_LUT_input);
    const input_t  *input  = (const input_t* )((const void*)f32_fminmax_LUT_input );
    const output_t *output = (const output_t*)((const void*)f32_fminmax_LUT_output);

    for (size_t i = 0; i < length; i++) {
        F32_pun f_min;
        F32_pun f_max;
        f_min.flt = fminf(input[i].x.flt, input[i].y.flt);
        f_max.flt = fmaxf(input[i].x.flt, input[i].y.flt);

        if (f_min.bin != output[i].f_min.bin || f_max.bin != output[i].f_max.bin) {
            if (
                !(
                    isnan(f_min.flt) && isnan(output[i].f_min.flt) &&
                    isnan(f_max.flt) && isnan(output[i].f_max.flt)
                )
            ) {
                test_printf(
                    "%zu:\nI: %08lX : %08lX\nG: %08lX < %08lX\nT: %08lX < %08lX\n",
                    i,
                    input[i].x.bin, input[i].y.bin,
                    f_min.bin, f_max.bin,
                    output[i].f_min.bin, output[i].f_max.bin
                );
                return i;
            }
        }
    }

    /* passed all */
    return SIZE_MAX;
}

#ifdef __cplusplus
extern "C" {
    int main(void);
}
#endif /* __cplusplus */

int main(void) {
    os_ClrHome();
    size_t fail_index = run_test();
    if (fail_index == SIZE_MAX) {
        puts("All tests passed");
    } else {
        char buf[sizeof("Failed test: 16777215")];
        boot_sprintf(buf, "Failed test: %u", fail_index);
        puts(buf);
    }

    while (!os_GetCSC());

    return 0;
}
$ make
fatal error: error in backend: unable to legalize instruction: %9:_(s1) = G_IS_FPCLASS %8:_(s32), 3 (in
      function: _ZNSt3__16__math5isnanB8nn190107Ef)
PLEASE submit a bug report to https://github.com/CE-Programming/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: C:\\Users\\zerico\\Programming\\ez80\\toolchain\\CEdev\\bin\\ez80-clang.exe -S -mllvm -profile-guided-section-prefix=false -mllvm -z80-gas-style -ffunction-sections -fdata-sections -fno-addrsig -fno-autolink -fno-threadsafe-statics -Wall -Wextra -Wshadow -Wformat=2 -Wconversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -O0 -ffreestanding -std=c17 C:/Users/zerico/Programming/ez80/toolchain/test/floating_point/float32_fminmax/obj/lto.bc -o C:/Users/zerico/Programming/ez80/toolchain/test/floating_point/float32_fminmax/obj/lto.s
1.      Code generation
2.      Running pass 'Function Pass Manager' on module 'C:/Users/zerico/Programming/ez80/toolchain/test/floating_point/float32_fminmax/obj/lto.bc'.
3.      Running pass 'Legalizer' on function '@_ZNSt3__16__math5isnanB8nn190107Ef'
Exception Code: 0xE0000046
0x75722404, C:\WINDOWS\System32\KERNELBASE.dll(0x00000000755C0000) + 0x162404 byte(s), RaiseException() + 0x64 byte(s)
0x007837D6, C:\Users\zerico\Programming\ez80\toolchain\CEdev\bin\ez80-clang.exe(0x00000000004D0000) + 0x2B37D6 byte(s)
0x01000000, C:\Users\zerico\Programming\ez80\toolchain\CEdev\bin\ez80-clang.exe(0x00000000004D0000) + 0xB30000 byte(s)
0x049D0100 <unknown module>
ez80-clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 17.0.6 (https://github.com/CE-Programming/llvm-project 262d0ad4ac4c788b0e865b638c397598e797c12c)
Target: ez80
Thread model: posix
InstalledDir: C:\Users\zerico\Programming\ez80\toolchain\CEdev\bin
ez80-clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
mingw32-make: *** [C:\Users\zerico\Programming\ez80\toolchain\CEdev\meta\makefile.mk:445: obj/lto.s] Error 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions