Unverified Commit 612e5d6a authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #5028 from RoryO/msvc-optimize-shuffle-bug

Work around MSC optimization generating non functional code with Array#shuffle
parents ac836000 ba9f81db
......@@ -101,6 +101,3 @@ jobs:
rake -E "STDOUT.sync=true" -m -j4 test
env:
MRUBY_CONFIG: appveyor_config.rb
# TODO(take-cheeze): Re-enable /O2
CFLAGS: "/c /nologo /W3 /we4013 /Zi /MD /D_CRT_SECURE_NO_WARNINGS"
CXXFLAGS: "/c /nologo /W3 /Zi /MD /EHs /D_CRT_SECURE_NO_WARNINGS"
version: "{build}"
os: Visual Studio 2017
shallow_clone: true
environment:
matrix:
# Visual Studio 2017 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
# Visual Studio 2017 32bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
- job_name: Visual Studio 2019 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
appveyor_build_worker_image: Visual Studio 2019
- job_name: Visual Studio 2019 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat
appveyor_build_worker_image: Visual Studio 2019
- job_name: Visual Studio 2017 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
appveyor_build_worker_image: Visual Studio 2017
- job_name: Visual Studio 2017 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat
appveyor_build_worker_image: Visual Studio 2017
- job_name: Visual Studio 2015 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86_amd64
- job_name: Visual Studio 2015 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86
# Visual Studio 2015 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: amd64
# Visual Studio 2015 32bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: x86
# Visual Studio 2013 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
machine: amd64
- job_name: Visual Studio 2013 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86_amd64
init:
- call "%visualcpp%" %machine%
# For using Rubyinstaller's Ruby 2.4 64bit
- set PATH=C:\Ruby24-x64\bin;%PATH%
# For using Rubyins4aller's Ruby 2.6 64bit
# 2.6 is the highest supported Ruby version across all historical
# Visual Studio AppVeyor images. Ruby 2.7 is only on the 2019 image.
- set PATH=C:\Ruby26-x64\bin;%PATH%
- ruby --version
build_script:
- set MRUBY_CONFIG=appveyor_config.rb
- rake -m
- rake -E $stdout.sync=true test
- rake -E "$stdout.sync=true" -m -j4 test
......@@ -218,6 +218,34 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary)
mrb_value r = mrb_nil_value();
rand_state *random;
/*
* MSC compiler bug generating invalid instructions with optimization
* enabled. MSC errantly uses a hardcoded value with optimizations on
* when using a fixed value from a union.
* Creating a temp volatile variable and reassigning back to the original
* value tricks the compiler to not perform this optimization;
*/
#if defined _MSC_VER && _MSC_VER >= 1923
/* C++ will not cast away volatile easily, so we cannot do something like
* volatile mrb_value rr = r; r = (mrb_value)rr; with C++.
* That cast does work with C.
* We also have to trick the compiler to not optimize away the const_cast entirely
* by creating and manipulating an intermediate volatile pointer.
*/
volatile mrb_value *v_r;
volatile mrb_int ii;
mrb_value *p_r;
v_r = &r;
ii = 2;
v_r = v_r + 2;
#if defined __cplusplus
p_r = const_cast<mrb_value*>(v_r - ii);
#else
p_r = (mrb_value*)v_r - ii;
#endif
r = *p_r;
#endif
if (RARRAY_LEN(ary) > 1) {
mrb_get_args(mrb, "|o", &r);
......
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