Skip to content

Commit

Permalink
Add a test for _Float16 ABI compatibility between clang and compiler-rt
Browse files Browse the repository at this point in the history
  • Loading branch information
tstellar committed Sep 2, 2023
1 parent 3ddcfd5 commit dc4c4a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ option(ENABLE_HWASAN
${SUPPORT_HWASAN}
)

# Check for _Float16 support
if (CLANGXX_BINARY)
message(STATUS "Checking for _Float16 support in ${CLANGXX_BINARY}")
execute_process(COMMAND ${CLANGXX_BINARY} -c ${CMAKE_CURRENT_SOURCE_DIR}/tests/float16.cpp RESULT_VARIABLE FLOAT16_STATUS ERROR_QUIET OUTPUT_QUIET)
if (${FLOAT16_STATUS} EQUAL 0)
message(STATUS "_Float16 enabled.")
set(ENABLE_FLOAT16 ON)
endif()
endif()

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.site.cfg.in
${CMAKE_BINARY_DIR}/tests/lit.site.cfg
Expand Down
15 changes: 15 additions & 0 deletions tests/float16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// REQUIRES: clang, compiler-rt, float16
// RUN: %clangxx %s -o %t.float16 -rtlib=compiler-rt
// RUN: %t.float16 | grep '0.122986'

#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
_Float16 one_f16 = 0.123;
float one_f32 = one_f16;
std::cout << one_f32 << std::endl;
return 0;
}
1 change: 1 addition & 0 deletions tests/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ enable_feature("libc++", "@ENABLE_LIBCXX@")
enable_feature("static-libc++", "@ENABLE_STATIC_LIBCXX@")
enable_feature("libunwind", "@ENABLE_LIBUNWIND@")
enable_feature("support_hwasan", "@ENABLE_HWASAN@")
enable_feature("float16", "@ENABLE_FLOAT16@")

0 comments on commit dc4c4a7

Please sign in to comment.