提交 5e345043 编写于 作者: M Megvii Engine Team

fix(cmake/bazel/clang): remove finite-math-only opt from Ofast,

for keep same build between gcc and clang

more detail:
```
 printf("%d\n", std::isnan(std::numeric_limits<float>::quiet_NaN()));
 printf("%d\n", std::isnan(std::nan("1")));
```

linux-clang and android-NDK clang have diff build logic with gcc and
macos/windows clang/clangcl
* clang++-12 -Ofast 1.cc
output is:
0
0

* clang++-12 -Ofast 1.cc -fno-finite-math-only
output is:
1
1

* g++ -Ofast 1.cc
output is:
1
1

GitOrigin-RevId: f0622e2ca019b0072fd6798990a8aba156c8022f
上级 cccddbc0
......@@ -167,7 +167,8 @@ if (NOT APPLE)
endif()
check_ipo_supported(RESULT IS_LTO_SUPPORT OUTPUT output_info)
if(IS_LTO_SUPPORT)
# LLVM on Windows report support LTO, but do not support -flto=full at link stage
if(IS_LTO_SUPPORT AND NOT WIN32)
message(STATUS "lto is supported in this compiler")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=full")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto=full")
......@@ -363,6 +364,14 @@ else()
else()
set(OPTIMIZE_LEVEL "-g -O3 -DNDEBUG")
endif()
#remove finite-math-only opt from Ofast, caused by clang have a different
#runtime finite math logic, this issue do not find at g++, but as a unity
#build flags, we force add -fno-finite-math-only when compiler support
CHECK_CXX_COMPILER_FLAG("-fno-finite-math-only" CXX_NO_FINITE_MATH_ONLY_SUPPORT)
if(CXX_NO_FINITE_MATH_ONLY_SUPPORT)
message(STATUS "force add -fno-finite-math-only for this compiler")
set(OPTIMIZE_LEVEL "${OPTIMIZE_LEVEL} -fno-finite-math-only")
endif()
set(CMAKE_C_FLAGS_RELEASE "${OPTIMIZE_LEVEL}")
set(CMAKE_CXX_FLAGS_RELEASE "${OPTIMIZE_LEVEL}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${OPTIMIZE_LEVEL}")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册