Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -360,6 +360,38 @@ append("/Zc:strictStrings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif(NOT (MSVC_VERSION LESS 1900)) + # /Zo (Enhance Optimized Debugging) was introduced with Visual Studio + # 2013 update 3. Instead of only enabling them in VS2013 update 3, we'll just + # enable them for Visual Studio 2015 (VS 14, MSVC_VERSION 1900) and up. + if (NOT (MSVC_VERSION LESS 1900)) + # "The /Zo compiler switch generates enhanced debugging information for + # optimized code. Optimization may use registers for local variables, + # reorder code, vectorize loops, and inline function calls. These + # optimizations can obscure the relationship between the source code and + # the compiled object code. The /Zo switch tells the compiler to generate + # additional debugging information for local variables and inlined + # functions. It also enables stack traces to show inlined functions in the + # WinDBG debugger. + # Debug builds that have disabled optimizations (/Od) do not need the + # additional debugging information generated when /Zo is specified." + append("/Zo" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + endif(NOT (MSVC_VERSION LESS 1900)) + + # /guard (Enable Control Flow Guard) was introduced with Visual Studio + # 2015. + if (NOT (MSVC_VERSION LESS 1900)) + # "The /guard:cf option causes the compiler to analyze control flow for + # indirect call targets at compile time, and then to insert code to + # verify the targets at runtime." + append("/guard:cf" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + # "The /guard:cf option must be passed to both the compiler and linker + # to build code that uses the CFG exploit mitigation technique." + append("/guard:cf" + CMAKE_EXE_LINKER_FLAGS + CMAKE_MODULE_LINKER_FLAGS + CMAKE_SHARED_LINKER_FLAGS) + endif(NOT (MSVC_VERSION LESS 1900)) + # "Generate Intrinsic Functions". append("/Oi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)