summaryrefslogtreecommitdiff
path: root/includes/Stg.h
diff options
context:
space:
mode:
authorTamar Christina <tamar@zhox.com>2018-01-26 13:10:10 -0500
committerBen Gamari <ben@smart-cactus.org>2018-01-26 14:37:29 -0500
commita55d581f8f2923560c3444253050b13fdf2dec10 (patch)
treea93dfe88e55530b362bf1cd15bc7dd928121749a /includes/Stg.h
parent9a57cfebd2e65109884712a27a0f29d1a71f57b7 (diff)
downloadhaskell-a55d581f8f2923560c3444253050b13fdf2dec10.tar.gz
Fix Windows stack allocations.
On Windows we use the function `win32AllocStack` to do stack allocations in 4k blocks and insert a stack check afterwards to ensure the allocation returned a valid block. The problem is this function does something that by C semantics is pointless. The stack allocated value can never escape the function, and the stack isn't used so the compiler just optimizes away the entire function body. After considering a bunch of other possibilities I think the simplest fix is to just disable optimizations for the function. Alternatively inline assembly is an option but the stack check function doesn't have a very portable name as it relies on e.g. `libgcc`. Thanks to Sergey Vinokurov for helping diagnose and test. Test Plan: ./validate Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14669 Differential Revision: https://phabricator.haskell.org/D4343
Diffstat (limited to 'includes/Stg.h')
-rw-r--r--includes/Stg.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/includes/Stg.h b/includes/Stg.h
index f377e50d98..2e023470ad 100644
--- a/includes/Stg.h
+++ b/includes/Stg.h
@@ -204,6 +204,16 @@
#define STG_UNUSED GNUC3_ATTRIBUTE(__unused__)
+/* Prevent functions from being optimized.
+ See Note [Windows Stack allocations] */
+#if defined(__clang__)
+#define STG_NO_OPTIMIZE __attribute__((optnone))
+#elif defined(__GNUC__) || defined(__GNUG__)
+#define STG_NO_OPTIMIZE __attribute__((optimize("O0")))
+#else
+#define STG_NO_OPTIMIZE /* nothing */
+#endif
+
/* -----------------------------------------------------------------------------
Global type definitions
-------------------------------------------------------------------------- */