This is an archive of the discontinued LLVM Phabricator instance.

Fix llvm build on MacOS
ClosedPublic

Authored by alsemenov on Oct 3 2022, 5:12 AM.

Details

Summary

On MacOS build fails with error

[1/1512] Building CXX object lib/Transforms/Utils/CMakeFiles/LLVMTransformUtils.dir/CodeLayout.cpp.o
FAILED: lib/Transforms/Utils/CMakeFiles/LLVMTransformUtils.dir/CodeLayout.cpp.o 
/Applications/Xcode11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/asemenov/w/llvm-project/build/lib/Transforms/Utils -I/Users/asemenov/w/llvm-project/llvm/lib/Transforms/Utils -I/Users/asemenov/w/llvm-project/build/include -I/Users/asemenov/w/llvm-project/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -g -isysroot /Applications/Xcode11.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk  -fno-exceptions -fno-rtti -std=c++17 -MD -MT lib/Transforms/Utils/CMakeFiles/LLVMTransformUtils.dir/CodeLayout.cpp.o -MF lib/Transforms/Utils/CMakeFiles/LLVMTransformUtils.dir/CodeLayout.cpp.o.d -o lib/Transforms/Utils/CMakeFiles/LLVMTransformUtils.dir/CodeLayout.cpp.o -c /Users/asemenov/w/llvm-project/llvm/lib/Transforms/Utils/CodeLayout.cpp
/Users/asemenov/w/llvm-project/llvm/lib/Transforms/Utils/CodeLayout.cpp:659:16: error: call to 'abs' is ambiguous
              (std::abs(CurGain.score() - BestGain.score()) < EPS &&
               ^~~~~~~~
/Applications/Xcode11.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/stdlib.h:132:6: note: candidate function
int      abs(int) __pure2;
         ^
/Applications/Xcode11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:111:44: note: candidate function
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                           ^
/Applications/Xcode11.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:113:44: note: candidate function
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
                                           ^
1 error generated.
[14/1512] Building CXX object lib/Transforms/Utils/CMakeFiles/LLVMTransformUtils.dir/InlineFunction.cpp.o
ninja: build stopped: subcommand failed

llvm/lib/Transforms/Utils/CodeLayout.cpp uses std::abs() with double argument, which is provided by cmath header, which is not explicitly included into CodeLayout.cpp. The implicit include in llvm/include/llvm/Support/MathExtras.h was removed in commit https://github.com/llvm/llvm-project/commit/16544cbe64b81a50800a88296ef37f4873a37b25

Inserting explicit include of cmath into /CodeLayout.cpp in order to fix build on MacOS

Diff Detail

Event Timeline

alsemenov created this revision.Oct 3 2022, 5:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 5:12 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
alsemenov requested review of this revision.Oct 3 2022, 5:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 5:12 AM
thieta accepted this revision.Oct 3 2022, 5:52 AM

LGTM.

This revision is now accepted and ready to land.Oct 3 2022, 5:52 AM
This revision was landed with ongoing or failed builds.Oct 3 2022, 7:51 AM
This revision was automatically updated to reflect the committed changes.