Commit 6ecf60a9 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

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
parent 4f6e47f9
...@@ -72,6 +72,7 @@ function(apply_folly_compile_options_to_target THETARGET) ...@@ -72,6 +72,7 @@ function(apply_folly_compile_options_to_target THETARGET)
target_compile_options(${THETARGET} target_compile_options(${THETARGET}
PUBLIC PUBLIC
/EHa # Enable both SEH and C++ Exceptions. /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:referenceBinding # Disallow temporaries from binding to non-const lvalue references.
/Zc:rvalueCast # Enforce the standard rules for explicit type conversion. /Zc:rvalueCast # Enforce the standard rules for explicit type conversion.
/Zc:implicitNoexcept # Enable implicit noexcept specifications where required, such as destructors. /Zc:implicitNoexcept # Enable implicit noexcept specifications where required, such as destructors.
...@@ -95,14 +96,12 @@ function(apply_folly_compile_options_to_target THETARGET) ...@@ -95,14 +96,12 @@ function(apply_folly_compile_options_to_target THETARGET)
# Debug builds # Debug builds
$<$<CONFIG:DEBUG>: $<$<CONFIG:DEBUG>:
/Gy- # Disable function level linking. /Gy- # Disable function level linking.
/GF- # Disable string pooling.
$<$<BOOL:${MSVC_ENABLE_DEBUG_INLINING}>:/Ob2> # Add /Ob2 if allowing inlining in debug mode. $<$<BOOL:${MSVC_ENABLE_DEBUG_INLINING}>:/Ob2> # Add /Ob2 if allowing inlining in debug mode.
> >
# Non-debug builds # Non-debug builds
$<$<NOT:$<CONFIG:DEBUG>>: $<$<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) /Gw # Optimize global data. (-fdata-sections)
/Gy # Enable function level linking. (-ffunction-sections) /Gy # Enable function level linking. (-ffunction-sections)
/Qpar # Enable parallel code generation. /Qpar # Enable parallel code generation.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment