We noticed this on 32-bit clang-cl builds. #include <cmath> float foo(double d) { return pow(2., d / 1200.); } > d:\clang7.0.1\bin\clang-cl -m32 -O2 -c exp2.cpp > dumpbin /all exp2.obj | findstr REL32 00000017 REL32 00000000 F _exp2 > d:\clang8rc1\bin\clang-cl -m32 -O2 -c exp2.cpp > dumpbin /all exp2.obj | findstr REL32 0000002C REL32 00000000 11 _pow At first glance I'm suspecting a bug in https://github.com/llvm/llvm-project/commit/2123ea7d5c722e98ce0f047c8baa3fb3db23e6b3.
Indeed, that patch fixed an issue when the call to exp2() would be emitted even when the run time environment didn't support it. LLVM assumes that Win32 only supports C89 math functions, which doesn't seem to be the case for a while anymore: https://is.gd/xFJPQw
Is this something that could be safely fixed within the 8.0.0 release?
I'm afraid that, as an enhancement, as you indicated above, it's too late for 8.0, since only bug fixes are being accepted now. My impression is that the Win32 library info needs an update, but, not working on targeting Windows, I'm unaware of how this would change the minimum requirements of LLVM in this OS. At https://is.gd/hTHTvX, it states that at least VC2015 is required to build LLVM. In my opinion, retargeting the Windows support to this version would be sensible, at least from what I could glean about it, albeit only on x86.
Reading the documentation in VS a bit more carefully, it seems that it still supports only C89. exp2() was not defined by C89, so LLVM uses this information describing run time library support that it assumes for Windows. However, reading the info on exp2() at https://is.gd/xFJPQw, it seems that VS supports a variation of C89. Specifically, just the double precision exp2(). I'll try to inventory the variations in the math library later.
Patch at https://reviews.llvm.org/D57625.
If this was a regression, have we identified the commit that caused this? I ask because I want to try to understand if this change was intended behavior.
(In reply to Reid Kleckner from comment #6) > If this was a regression, have we identified the commit that caused this? I > ask because I want to try to understand if this change was intended behavior. r341095, primarily about expanding the optimizations around pow, additionally fixed a bug where exp2 would be emitted even when the TargetLibraryInfo didn't support it. Turns out Windows builds were inadvertently relying on that behavior, because that target (wrongly) thinks exp2 isn't supported.
David, Could you please provide the output when running either clang-cl command above with the option --verbose? Thank you.
Do you mean `-v`? The `--verbose` option isn't recognized. What part of the output are you looking for?
OK, could you please build an executable and provide a verbose output showing both how the compiler is invoked and all the libraries linked in?
It would save us some round trips if you'd spell out precisely what command you'd like me to run, otherwise I am likely to misunderstand your request.
Sorry, I'm not a Windows user. Based on the clang documentation, here's what I think the commands should be. Please, try: clang-cl -m32 -O2 -c exp2.cpp -o exp2.o -v And then: clang-cl -m32 exp2.o -o exp2.exe -v Thank you.
E:\repro\exp2>type exp2.cpp #include <cmath> int main(int argc, char** argv) { return pow(2., argc); } E:\repro\exp2>d:\clang8rc1\bin\clang-cl -m32 -O2 -c exp2.cpp -o exp2.o -v clang version 8.0.0 (tags/RELEASE_800/rc1 352000) Target: i386-pc-windows-msvc Thread model: posix InstalledDir: d:\clang8rc1\bin "d:\\clang8rc1\\bin\\clang-cl.exe" -cc1 -triple i386-pc-windows-msvc19.16.27026 -emit-obj -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name exp2.cpp -mrelocation-model static -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -mllvm -x86-asm-syntax=intel -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fms-volatile -fdiagnostics-format msvc -dwarf-column-info -momit-leaf-frame-pointer -v -ffunction-sections -coverage-notes-file "E:\\repro\\exp2\\exp2.gcno" -resource-dir "d:\\clang8rc1\\lib\\clang\\8.0.0" -internal-isystem "d:\\clang8rc1\\lib\\clang\\8.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17134.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17134.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17134.0\\winrt" -O2 -fdeprecated-macro -fdebug-compilation-dir "E:\\repro\\exp2" -ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.16.27026 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o exp2.o -x c++ exp2.cpp -faddrsig clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-windows-msvc #include "..." search starts here: #include <...> search starts here: d:\clang8rc1\lib\clang\8.0.0\include C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt End of search list. E:\repro\exp2>d:\clang8rc1\bin\clang-cl -m32 exp2.o -o exp2.exe -v clang version 8.0.0 (tags/RELEASE_800/rc1 352000) Target: i386-pc-windows-msvc Thread model: posix InstalledDir: d:\clang8rc1\bin "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x86\\link.exe" -out:exp2.exe "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\lib\\x86" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17134.0\\ucrt\\x86" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17134.0\\um\\x86" -nologo exp2.o
Checked https://reviews.llvm.org/D57625 in.
(In reply to Evandro Menezes from comment #14) > Checked https://reviews.llvm.org/D57625 in. Great, thank you! Just to double check, are you still thinking that this should not be backported to 8.0?
I'll try, after broad testing happens.
LLVM described the Windows runtime library incorrectly, which D49273 exposed. The runtime support, at least for math functions, was updated in D57625 and rL353758.
I'm okay with merging r353733, but let's allow it to "bake" in trunk a little longer first.
I agree. r353733 and r353758 have been in the oven for nearly 24h now. Methinks that in 12h or so they'll be done out of the baking and ready to serve. Yes? Thank you.
It turns out there was a lot of refactoring to these files lately. Merged r352707, r352714, r352886, r352892, r352895, r352908, r352917, r352935, r353213, r353733, and r353758 to release_80 in r353934.
(In reply to Hans Wennborg from comment #20) > Merged r352707, r352714, r352886, r352892, r352895, r352908, r352917, > r352935, r353213, r353733, and r353758 to release_80 in r353934. Thank you.