From df6291a666d3be784e2bbd00e4dbcdcceaf0196f Mon Sep 17 00:00:00 2001 From: Mehdi Chinoune Date: Mon, 20 Jun 2022 12:39:00 -0700 Subject: [PATCH] [CMake][MSVC] Compile with `/permissive-` This turns off a bunch of non-standard behaviors in MSVC. LLVM, as a portable codebase, should build correctly without those behaviors. Note that `/permissive-` implies `/Zc:strictStrings` and `/Zc:rvalueCast`. See also: https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance Differential Revision: https://reviews.llvm.org/D125263 --- llvm/cmake/modules/HandleLLVMOptions.cmake | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index f39ec2c..56d05f5 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -522,17 +522,9 @@ if( MSVC ) endif() endif() - # Disable string literal const->non-const type conversion. - # "When specified, the compiler requires strict const-qualification - # conformance for pointers initialized by using string literals." - append("/Zc:strictStrings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - # "Generate Intrinsic Functions". append("/Oi" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) - # "Enforce type conversion rules". - append("/Zc:rvalueCast" CMAKE_CXX_FLAGS) - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO) # clang-cl and cl by default produce non-deterministic binaries because # link.exe /incremental requires a timestamp in the .obj file. clang-cl @@ -561,6 +553,10 @@ if( MSVC ) # but in many objects files need more than that. This flag is to increase the # number of sections. append("/bigobj" CMAKE_CXX_FLAGS) + + # Enable standards conformance mode. + # This ensures handling of various C/C++ constructs is more similar to other compilers. + append("/permissive-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif( MSVC ) # Warnings-as-errors handling for GCC-compatible compilers: -- 2.7.4