From 6ecf60a979c5eb5d4e4edd0cd59393bb1c1931af Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Thu, 13 Jul 2017 10:57:07 -0700 Subject: [PATCH] Force string pooling to workaround a codegen bug Summary: There are bugs in MSVC's codegen that causes `StringPiece`'s evaluated in a `constexpr` context to have the start pointer point to one copy of the string and the end pointer point to another. Using the `StringPiece` at compile-time is perfectly fine, it just has the wrong values at runtime. We can work around this issue by enabling string pooling in all modes. Original bug report: https://developercommunity.visualstudio.com/content/problem/3216/c-incorrect-data-duplication-in-constexpr-context.html Reviewed By: yfeldblum Differential Revision: D5409753 fbshipit-source-id: 24e2b343209ba7c86d0dd39a1358d0abe9ee6d4d --- CMake/FollyCompiler.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMake/FollyCompiler.cmake b/CMake/FollyCompiler.cmake index 5b0058a7..70dfe378 100755 --- a/CMake/FollyCompiler.cmake +++ b/CMake/FollyCompiler.cmake @@ -72,6 +72,7 @@ function(apply_folly_compile_options_to_target THETARGET) target_compile_options(${THETARGET} PUBLIC /EHa # Enable both SEH and C++ Exceptions. + /GF # There are bugs with constexpr StringPiece when string pooling is disabled. /Zc:referenceBinding # Disallow temporaries from binding to non-const lvalue references. /Zc:rvalueCast # Enforce the standard rules for explicit type conversion. /Zc:implicitNoexcept # Enable implicit noexcept specifications where required, such as destructors. @@ -95,14 +96,12 @@ function(apply_folly_compile_options_to_target THETARGET) # Debug builds $<$: /Gy- # Disable function level linking. - /GF- # Disable string pooling. $<$:/Ob2> # Add /Ob2 if allowing inlining in debug mode. > # Non-debug builds $<$>: - /GF # Enable string pooling. (this is enabled by default by the optimization level, but we enable it here for clarity) /Gw # Optimize global data. (-fdata-sections) /Gy # Enable function level linking. (-ffunction-sections) /Qpar # Enable parallel code generation. -- 2.34.1