Skip to content

Halide headers fail to compile for wasm32-wasip1 due to incorrect _Float16 detection #8986

@hpcnt-daniel-l

Description

@hpcnt-daniel-l

Summary

When using the Halide headers with a Clang toolchain targeting wasm32-wasip1, compilation fails because Halide's feature detection incorrectly assumes _Float16 support is available.

Minimal Reproducible Example

test.cpp

#include <Halide.h>
int main() { return 0; }

Compilation Command:

clang++ --target=wasm32-wasip1 -std=c++17 \
  -I/path/to/Halide-21.0.0-arm-64-osx/include \
  -c test.cpp -o test.o

Actual Result

The compiler fails with the following error:

/path/to/Halide-21.0.0-arm-64-osx/include/HalideRuntime.h:2156:61: error:
      _Float16 is not supported on this target
 2156 | HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<_Float16>() {
      |                                                          ^

Expected Result

The headers should compile successfully. If the target (WASM) does not support _Float16, Halide should automatically disable the corresponding halide_type_of helpers.

Analysis / Workaround

  • In src/runtime/HalideRuntime.h, Halide enables HALIDE_CPP_COMPILER_HAS_FLOAT16 for clang using the __is_identifier(_Float16) check, but it seems this is not enough to ensure that _Float16 is actually supported on the target.
  • For wasm32-wasip1, that detection appears to succeed even though clang later rejects actual _Float16 usage on that target.
  • Emscripten does not hit this because Halide already excludes __EMSCRIPTEN__ in that detection path.
  • I can work around this by defining HALIDE_RUNTIME_ASAN_DETECTED to disable _Float16 support, but this is not ideal since that flag is not intended for this purpose.

Suggested Fixes

  1. Add && !defined(__wasm__) to the clang _Float16 auto-detection path.
  2. Add a dedicated opt-out macro such as HALIDE_DISABLE_CPP_FLOAT16, rather than requiring users to define HALIDE_RUNTIME_ASAN_DETECTED for this purpose.

Environment

  • Halide Version: 21.0.0
  • Compiler: Homebrew Clang 21.1.8
  • OS: macOS 26.3

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