From: Christopher Dykes <cdykes@fb.com>
Date: Thu, 13 Jul 2017 17:57:07 +0000 (-0700)
Subject: Force string pooling to workaround a codegen bug
X-Git-Tag: v2017.07.17.00~13
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6ecf60a979c5eb5d4e4edd0cd59393bb1c1931af;p=folly.git

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
---

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
       $<$<CONFIG:DEBUG>:
         /Gy- # Disable function level linking.
-        /GF- # Disable string pooling.
 
         $<$<BOOL:${MSVC_ENABLE_DEBUG_INLINING}>:/Ob2> # Add /Ob2 if allowing inlining in debug mode.
       >
 
       # Non-debug builds
       $<$<NOT:$<CONFIG:DEBUG>>:
-        /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.