Define _HAS_EXCEPTIONS=0, when compiling benchmark files, to disable exceptions in Microsoft STL.
Windows builds were failing due to C4530 warnings (C++ exception handler used, but unwind semantics are not enabled) thrown by MSVC standard library.
Differential D52998
[benchmark] Disable exceptions in Microsoft STL eandrews on Oct 8 2018, 1:54 PM. Authored by
Details Define _HAS_EXCEPTIONS=0, when compiling benchmark files, to disable exceptions in Microsoft STL. Windows builds were failing due to C4530 warnings (C++ exception handler used, but unwind semantics are not enabled) thrown by MSVC standard library.
Diff Detail
Event TimelineComment Actions Are those warnings about C++ exceptions, or some windows-specific exception stuff? Comment Actions I do not think defining _HAS_EXCEPTIONS=0 affects C++ exceptions in the application. I thought it only affected the STL. I will verify this and update you. Comment Actions _HAS_EXCEPTIONS=0 is an undocumented STL specific thing that the library Comment Actions Thanks for the information Zachary. @lebedev.ri I do not know how benchmark library developers need/want to handle exceptions in MSVC STL. If these need to be enabled when BENCHMARK_ENABLE_EXCEPTIONS is true, I think we can just modify _HAS_EXCEPTIONS in utils/benchmark/CMakeLists.txt. Comment Actions It's not enough to just set _HAS_EXCEPTIONS=1, it has to match whatever the value of /EH is passed to the compiler. So if we need to be able to throw catch exceptions, then you should pass /EHsc and not touch _HAS_EXCEPTIONS (technically you could set it to 1 but that's the default). And if we don't need to be able to throw or catch exceptions, then we pass /EHs-c- (which is what we do today) and also set _HAS_EXCEPTIONS=0. But the two should agree with each other. Comment Actions Yes. I understand. At the moment, exception handling flags are generated based on BENCHMARK_ENABLE_EXCEPTIONS in utils/benchmark/CMakeLists.txt . However, _HAS_EXCEPTIONS is not defined based on this (code below). The warnings are a result of this mismatch. if (NOT BENCHMARK_ENABLE_EXCEPTIONS) add_cxx_compiler_flag(-EHs-) add_cxx_compiler_flag(-EHa-) endif() I think it makes most sense to add definition for _HAS_EXCEPTIONS=0 here as opposed to modifying llvm/CMakeLists.txt. Please correct me if I'm wrong. I'm not too familiar with CMake. @kbobyrev Please let me know what you think as well since you had suggested llvm/CMakeLists.txt. Comment Actions @kbobyrev I apologize if I was unclear in the comments. I was asking if the changes proposed in the comments are alright with you since they would involve modifying benchmark/CMakelists.txt (instead of llvm/CMakeLists.txt as discussed in mailing list). As Zachary mentioned in comments, _HAS_EXCEPTIONS should be set to 0 only when exceptions are disabled. Since exception handling for benchmarks is handled in benchmark/CMakeLists.txt, I think it makes most sense to add the definition there. I have now uploaded the proposed change for review. I am still working with my company to figure out the corporate CLA Google's benchmark project requires for patch submissions. I can submit the patch upstream once that is done. If you would prefer to submit the patch upstream yourself, please feel free to do so. Sorry again for the confusion! Comment Actions Ah, my bad, I didn't notice it's the utils/benchmark/CMakeLists.txt :( Apologies. Upstreaming it first might be better, especially since the change seems to be trivial. Is this line addition the only change proposed for the benchmark library? If so, I could submit a PR and probably get it accepted within the next few days. Then this patch would simply add commit hash and small notice to utils/benchmark/README.LLVM and that would be it. Do you want me to submit the patch to the benchmark library? It seems that it would help to speedup the process. Comment Actions
Yes this line is the only change.
That would be helpful. Thank you! Comment Actions The patch is good to go! Please add the commit reference to utils/benchmark/README.LLVM (https://github.com/google/benchmark/commit/a9b31c51b1ee7ec7b31438c647123c2cbac5d956) and the patch could be landed! |