Force string pooling to workaround a codegen bug
authorChristopher Dykes <cdykes@fb.com>
Thu, 13 Jul 2017 17:57:07 +0000 (10:57 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 13 Jul 2017 18:06:30 +0000 (11:06 -0700)
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

index 5b0058a7fc6f774c524558ce5f21aa4d88dd6573..70dfe378674771683bfc3af03fac6a476f13bafb 100755 (executable)
@@ -72,6 +72,7 @@ function(apply_folly_compile_options_to_target THETARGET)
   target_compile_options(${THETARGET}\r
     PUBLIC\r
       /EHa # Enable both SEH and C++ Exceptions.\r
+      /GF # There are bugs with constexpr StringPiece when string pooling is disabled.\r
       /Zc:referenceBinding # Disallow temporaries from binding to non-const lvalue references.\r
       /Zc:rvalueCast # Enforce the standard rules for explicit type conversion.\r
       /Zc:implicitNoexcept # Enable implicit noexcept specifications where required, such as destructors.\r
@@ -95,14 +96,12 @@ function(apply_folly_compile_options_to_target THETARGET)
       # Debug builds\r
       $<$<CONFIG:DEBUG>:\r
         /Gy- # Disable function level linking.\r
-        /GF- # Disable string pooling.\r
 \r
         $<$<BOOL:${MSVC_ENABLE_DEBUG_INLINING}>:/Ob2> # Add /Ob2 if allowing inlining in debug mode.\r
       >\r
 \r
       # Non-debug builds\r
       $<$<NOT:$<CONFIG:DEBUG>>:\r
-        /GF # Enable string pooling. (this is enabled by default by the optimization level, but we enable it here for clarity)\r
         /Gw # Optimize global data. (-fdata-sections)\r
         /Gy # Enable function level linking. (-ffunction-sections)\r
         /Qpar # Enable parallel code generation.\r