From f0770609f8cdbeba019b35af48b70840f33bd479 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 11 Feb 2019 23:19:44 -0800 Subject: [PATCH] Support building with VS2019 Preview (#22525) * Support building with VS2019 Preview * Fixing gen-buildsys-win to only set the architecture for the VS generator * Refactoring Dev11/147911/fpcw.cpp so that it compiles under VS2019 * Removing the remaining traces of VS2015 build support --- CMakeLists.txt | 6 +- .../building/windows-instructions.md | 12 +- build-test.cmd | 12 +- build.cmd | 12 +- setup_vs_tools.cmd | 30 +-- src/dlls/mscoree/coreclr/CMakeLists.txt | 5 - src/pal/tools/gen-buildsys-win.bat | 18 +- tests/runtest.cmd | 25 +-- .../regressions/Dev11/147911/fpcw.cpp | 210 ++++++++++-------- 9 files changed, 171 insertions(+), 159 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ac693b0bee7..d988ef258c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,11 +54,7 @@ if (WIN32) endif() # Explicitly specify the assembler to be used for Arm32 compile - if($ENV{__VSVersion} STREQUAL "vs2015") - file(TO_CMAKE_PATH "$ENV{VCINSTALLDIR}\\bin\\x86_arm\\armasm.exe" CMAKE_ASM_COMPILER) - else() - file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER) - endif() + file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER) set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER}) message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}") diff --git a/Documentation/building/windows-instructions.md b/Documentation/building/windows-instructions.md index cfd6293e3bf8..b5261488952f 100644 --- a/Documentation/building/windows-instructions.md +++ b/Documentation/building/windows-instructions.md @@ -11,13 +11,8 @@ You must install several components to build the CoreCLR and CoreFX repos. These ## Visual Studio Visual Studio must be installed. Supported versions: -- [Visual Studio 2015](https://www.visualstudio.com/vs/older-downloads/) (Community, Professional, Enterprise). The community version is completely free. - [Visual Studio 2017](https://www.visualstudio.com/downloads/) (Community, Professional, Enterprise). The community version is completely free. - -For Visual Studio 2015: -* Ensure you have installed at least [Visual Studio 2015 Update 3](https://www.visualstudio.com/en-us/news/releasenotes/vs2015-update3-vs). -* Make sure that you install "VC++ Tools". By default, they will not be installed. -* To build for Arm32, Make sure that you have the Windows SDK for Windows 10 installed (or selected to be installed as part of VS installation). To explicitly install Windows SDK, download it from here: [Windows SDK for Windows 10](https://developer.microsoft.com/en-us/windows/downloads) +- [Visual Studio 2019 Preview](https://visualstudio.microsoft.com/vs/preview/) (Community, Professional, Enterprise). The community version is completely free. For Visual Studio 2017: * When doing a 'Workloads' based install, the following are the minimum requirements: @@ -50,7 +45,6 @@ For Visual Studio 2017: * **Important:** You must have the `msdia120.dll` COM Library registered in order to build the repository. * This binary is registered by default when installing the "VC++ Tools" with Visual Studio 2015 * You can also manually register the binary by launching the "Developer Command Prompt for VS2017" with Administrative privileges and running `regsvr32.exe "%VSINSTALLDIR%\Common7\IDE\msdia120.dll"` -* **Important:** By default, the build will attempt to use VS2015 as the toolset for the build. To build using VS2017 as your toolset, you must use the "Developer Command Prompt for VS2017". Visual Studio Express is not supported. @@ -75,7 +69,7 @@ any recent (2.4+) version of Python should work, including Python 3. ## Git -For actual user operations, it is often more convenient to use the GIT features built into Visual Studio 2015. +For actual user operations, it is often more convenient to use the GIT features built into Visual Studio. However the CoreCLR and the tests use the GIT command line utilities directly so you need to install them for these to work properly. You can get it from @@ -93,7 +87,7 @@ Powershell version must be 3.0 or higher. This should be the case for Windows 8 ## DotNet Core SDK While not strictly needed to build or test the .NET Core repository, having the .NET Core SDK installed lets you use the dotnet.exe command to run .NET Core applications in the 'normal' way. We use this in the -[Using Your Build](../workflow/UsingYourBuild.md) instructions. Visual Studio 2015 (update 3) should have +[Using Your Build](../workflow/UsingYourBuild.md) instructions. Visual Studio should have installed the .NET Core SDK, but in case it did not you can get it from the [Installing the .Net Core SDK](https://www.microsoft.com/net/core) page. ## Adding to the default PATH variable diff --git a/build-test.cmd b/build-test.cmd index 0c1ded3ba8f0..53b2fe7ab5f8 100644 --- a/build-test.cmd +++ b/build-test.cmd @@ -12,14 +12,14 @@ set __ThisScriptDir="%~dp0" call "%__ThisScriptDir%"\setup_vs_tools.cmd if NOT '%ERRORLEVEL%' == '0' exit /b 1 -if defined VS150COMNTOOLS ( +if defined VS160COMNTOOLS ( + set "__VSToolsRoot=%VS160COMNTOOLS%" + set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build" + set __VSVersion=vs2019 +) else if defined VS150COMNTOOLS ( set "__VSToolsRoot=%VS150COMNTOOLS%" set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build" set __VSVersion=vs2017 -) else ( - set "__VSToolsRoot=%VS140COMNTOOLS%" - set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC" - set __VSVersion=vs2015 ) :: Set the default arguments for build @@ -633,7 +633,7 @@ at the install location of previous Visual Studio version. The workaround is to of the previous version to "%VSINSTALLDIR%" and then build. REM DIA SDK not included in Express editions echo Visual Studio Express does not include the DIA SDK. ^ -You need Visual Studio 2015 or 2017 (Community is free). +You need Visual Studio 2017 or 2019 (Community is free). echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites exit /b 1 diff --git a/build.cmd b/build.cmd index dec253b5e35e..b1e773139c41 100644 --- a/build.cmd +++ b/build.cmd @@ -13,14 +13,14 @@ set __ThisScriptDir="%~dp0" call "%__ThisScriptDir%"\setup_vs_tools.cmd if NOT '%ERRORLEVEL%' == '0' exit /b 1 -if defined VS150COMNTOOLS ( +if defined VS160COMNTOOLS ( + set "__VSToolsRoot=%VS160COMNTOOLS%" + set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build" + set __VSVersion=vs2019 +) else if defined VS150COMNTOOLS ( set "__VSToolsRoot=%VS150COMNTOOLS%" set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build" set __VSVersion=vs2017 -) else ( - set "__VSToolsRoot=%VS140COMNTOOLS%" - set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC" - set __VSVersion=vs2015 ) :: Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment @@ -1056,6 +1056,6 @@ at the install location of previous Visual Studio version. The workaround is to of the previous version to "%VSINSTALLDIR%" and then build. REM DIA SDK not included in Express editions echo Visual Studio Express does not include the DIA SDK. ^ -You need Visual Studio 2015 or 2017 (Community is free). +You need Visual Studio 2017 or 2019 (Community is free). echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites exit /b 1 diff --git a/setup_vs_tools.cmd b/setup_vs_tools.cmd index 9af06e5bdd1d..24e8b230cab8 100644 --- a/setup_vs_tools.cmd +++ b/setup_vs_tools.cmd @@ -1,42 +1,36 @@ @if not defined _echo @echo off -REM This script is responsible for setting up either the vs2015 or vs2017 env +REM This script is responsible for setting up the vs2017 or vs2019 env REM All passed arguments are ignored REM Script will return with 0 if pass, 1 if there is a failure to find either -REM vs2015 or vs2017 +REM vs2017 or vs2019 :: Default to highest Visual Studio version available :: -:: For VS2015 (and prior), only a single instance is allowed to be installed on a box -:: and VS140COMNTOOLS is set as a global environment variable by the installer. This -:: allows users to locate where the instance of VS2015 is installed. -:: -:: For VS2017, multiple instances can be installed on the same box SxS and VS150COMNTOOLS +:: For VS2017 and later, multiple instances can be installed on the same box SxS and VS1*0COMNTOOLS :: is no longer set as a global environment variable and is instead only set if the user -:: has launched the VS2017 Developer Command Prompt. +:: has launched the Visual Studio Developer Command Prompt. :: -:: Following this logic, we will default to the VS2017 toolset if VS150COMNTOOLS tools is -:: set, as this indicates the user is running from the VS2017 Developer Command Prompt and -:: is already configured to use that toolset. Otherwise, we will fallback to using the VS2015 -:: toolset if it is installed. Finally, we will fail the script if no supported VS instance -:: can be found. +:: Following this logic, we will default to the Visual Studio toolset assocated with the active +:: Developer Command Prompt. Otherwise, we will query VSWhere to locate the later version of +:: Visual Studio available on the machine. Finally, we will fail the script if not supported +:: instance can be found. if defined VisualStudioVersion ( if not defined __VSVersion echo %__MsgPrefix%Detected Visual Studio %VisualStudioVersion% developer command ^prompt environment goto skip_setup ) -echo %__MsgPrefix%Searching ^for Visual Studio 2017 or 2015 installation +echo %__MsgPrefix%Searching ^for Visual Studio 2017 or later installation set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if exist %_VSWHERE% ( for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools goto call_vs ) -if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS% -echo VS2017 not found, using VS2015 +echo Visual Studio 2017 or later not found :call_vs if not exist "%_VSCOMNTOOLS%" ( - echo %__MsgPrefix%Error: Visual Studio 2015 or 2017 required. + echo %__MsgPrefix%Error: Visual Studio 2017 or 2019 required. echo Please see https://github.com/dotnet/coreclr/blob/master/Documentation/building/windows-instructions.md for build instructions. exit /b 1 ) @@ -45,4 +39,4 @@ call "%_VSCOMNTOOLS%\VsDevCmd.bat" :skip_setup -exit /b 0 \ No newline at end of file +exit /b 0 diff --git a/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/dlls/mscoree/coreclr/CMakeLists.txt index 072965250a81..380c8ddfdef5 100644 --- a/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -168,11 +168,6 @@ if(WIN32) endif() set(DACTABLEGEN_EXE ${CMAKE_BINARY_DIR}/src/ToolBox/SOS/DacTableGen/dactablegen.exe) - # The DactTableGen executable that we build needs an msdia140.dll supplied by Visual Studio. - # however VS2015 may not have this, so fall back to the DactTableGen in the tools package (which is old) - if($ENV{__VSVersion} STREQUAL "vs2015") - set(DACTABLEGEN_EXE ${BuildToolsDir}/dactablegen.exe) - endif() add_custom_command( DEPENDS coreclr mscordaccore mscordbi ${CLR_DIR}/src/debug/daccess/daccess.cpp diff --git a/src/pal/tools/gen-buildsys-win.bat b/src/pal/tools/gen-buildsys-win.bat index f542e994e72d..87b0dee77c21 100644 --- a/src/pal/tools/gen-buildsys-win.bat +++ b/src/pal/tools/gen-buildsys-win.bat @@ -19,13 +19,17 @@ set __SourceDir=%1 set __VSVersion=%2 set __Arch=%3 set __CmakeGenerator=Visual Studio -if /i "%__VSVersion%" == "vs2017" (set __CmakeGenerator=%__CmakeGenerator% 15 2017) -if /i "%__VSVersion%" == "vs2015" (set __CmakeGenerator=%__CmakeGenerator% 14 2015) -if /i "%__Arch%" == "x64" (set __CmakeGenerator=%__CmakeGenerator% Win64) -if /i "%__Arch%" == "arm" (set __CmakeGenerator=%__CmakeGenerator% ARM) -if /i "%__Arch%" == "arm64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM64) -if /i "%__NMakeMakefiles%" == "1" (set __CmakeGenerator=NMake Makefiles) +if /i "%__NMakeMakefiles%" == "1" ( + set __CmakeGenerator=NMake Makefiles +) else ( + if /i "%__VSVersion%" == "vs2019" (set __CmakeGenerator=%__CmakeGenerator% 16 2019) + if /i "%__VSVersion%" == "vs2017" (set __CmakeGenerator=%__CmakeGenerator% 15 2017) + + if /i "%__Arch%" == "x64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64) + if /i "%__Arch%" == "arm" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM) + if /i "%__Arch%" == "arm64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM64) +) :loop if [%4] == [] goto end_loop @@ -48,7 +52,7 @@ GOTO :DONE echo "Usage..." echo "gen-buildsys-win.bat " echo "Specify the path to the top level CMake file - /src/NDP" - echo "Specify the VSVersion to be used - VS2015 or VS2017" + echo "Specify the VSVersion to be used - VS2017 or VS2019" EXIT /B 1 :DONE diff --git a/tests/runtest.cmd b/tests/runtest.cmd index 47efe4f2ddfe..a31ee475b933 100644 --- a/tests/runtest.cmd +++ b/tests/runtest.cmd @@ -16,10 +16,10 @@ if /I "%PROCESSOR_ARCHITEW6432%"=="arm64" goto :skip_vs_setup call "%__ThisScriptDir%"\..\setup_vs_tools.cmd if NOT '%ERRORLEVEL%' == '0' exit /b 1 -if defined VS150COMNTOOLS ( +if defined VS160COMNTOOLS ( + set __VSVersion=vs2019 +) else if defined VS150COMNTOOLS ( set __VSVersion=vs2017 -) else ( - set __VSVersion=vs2015 ) :skip_vs_setup @@ -73,8 +73,8 @@ if /i "%1" == "debug" (set __BuildType=Debug&s if /i "%1" == "release" (set __BuildType=Release&shift&goto Arg_Loop) if /i "%1" == "checked" (set __BuildType=Checked&shift&goto Arg_Loop) -if /i "%1" == "vs2015" (set __VSVersion=%1&shift&goto Arg_Loop) if /i "%1" == "vs2017" (set __VSVersion=%1&shift&goto Arg_Loop) +if /i "%1" == "vs2019" (set __VSVersion=%1&shift&goto Arg_Loop) if /i "%1" == "TestEnv" (set __TestEnv=%2&shift&shift&goto Arg_Loop) if /i "%1" == "AgainstPackages" (set __AgainstPackages=1&shift&goto Arg_Loop) @@ -242,17 +242,16 @@ exit /b %ERRORLEVEL% :: Set up msbuild and tools environment. Check if msbuild and VS exist. set _msbuildexe= -if /i "%__VSVersion%" == "vs2017" ( +if /i "%__VSVersion%" == "vs2019" ( + set "__VSToolsRoot=%VS160COMNTOOLS%" + set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build" + + set _msbuildexe="%VS160COMNTOOLS%\..\..\MSBuild\Current\Bin\MSBuild.exe" +) else if /i "%__VSVersion%" == "vs2017" ( set "__VSToolsRoot=%VS150COMNTOOLS%" set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build" set _msbuildexe="%VS150COMNTOOLS%\..\..\MSBuild\15.0\Bin\MSBuild.exe" -) else if /i "%__VSVersion%" == "vs2015" ( - set "__VSToolsRoot=%VS140COMNTOOLS%" - set "__VCToolsRoot=%VS140COMNTOOLS%\..\..\VC" - - set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" - if not exist !_msbuildexe! set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe" ) :: Does VS really exist? @@ -723,7 +722,7 @@ echo. echo./? -? /h -h /help -help - View this message. echo ^ - Specifies build architecture: x64, x86, arm, or arm64 ^(default: x64^). echo ^ - Specifies build type: Debug, Release, or Checked ^(default: Debug^). -echo VSVersion ^ - VS2015 or VS2017 ^(default: VS2017^). +echo VSVersion ^ - VS2017 or VS2019 ^(default: VS2019^). echo TestEnv ^ - Run a custom script before every test to set custom test environment settings. echo AgainstPackages - This indicates that we are running tests that were built against packages. echo GenerateLayoutOnly - If specified will not run the tests and will only create the Runtime Dependency Layout @@ -769,6 +768,6 @@ echo %0 x64 release exit /b 1 :NoVS -echo Visual Studio 2015 or 2017 ^(Community is free^) is a prerequisite to build this repository. +echo Visual Studio 2017 or 2019 ^(Community is free^) is a prerequisite to build this repository. echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites exit /b 1 diff --git a/tests/src/baseservices/exceptions/regressions/Dev11/147911/fpcw.cpp b/tests/src/baseservices/exceptions/regressions/Dev11/147911/fpcw.cpp index f8e581a7690e..cfd60f2d4320 100644 --- a/tests/src/baseservices/exceptions/regressions/Dev11/147911/fpcw.cpp +++ b/tests/src/baseservices/exceptions/regressions/Dev11/147911/fpcw.cpp @@ -15,17 +15,17 @@ LONG WINAPI ExcepFilter(struct _EXCEPTION_POINTERS *pExp) printf( "In ExcepFilter \n" ); if (pExp->ExceptionRecord->ExceptionCode == 0xc00002b5 || - pExp->ExceptionRecord->ExceptionCode == 0xc00002b4 ) + pExp->ExceptionRecord->ExceptionCode == 0xc00002b4 ) return EXCEPTION_EXECUTE_HANDLER; else return EXCEPTION_CONTINUE_SEARCH; } - // This is an example of an exported function. // Disable optimization otherwise compiler removes dividebyzero operation #pragma optimize( "", off ) -extern "C" FPCW_API int RaiseFPException(void) + +int TestDivByZero(void) { unsigned int fpcw; @@ -40,20 +40,39 @@ extern "C" FPCW_API int RaiseFPException(void) return -1; } - __try - { __try { - float d = 2.0 - (0.0+2.0); - float f = 2.0f/d; - printf("Shouldn't execute!\n"); - (void)f; // nop to disable warning C4189 - return 99; + __try + { + float d = 2.0 - (0.0+2.0); + float f = 2.0f/d; + printf("Shouldn't execute!\n"); + (void)f; // nop to disable warning C4189 + return 99; + } + __except((GetExceptionCode()==0xc000008e)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) + { + printf("Caught exception!\n"); + + // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in + // FPU raising the exception again. + _clearfp(); + + // Reset FPCW + err = _controlfp_s(&fpcw, 0x1f, _MCW_EM); + if (err) + { + printf("Error setting FPCW: %d\n", err); + return -1; + } + + printf("Passed\n"); + } } - __except((GetExceptionCode()==0xc000008e)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) + __except(ExcepFilter(GetExceptionInformation())) { - printf("Caught exception!\n"); - + printf("Caught exception in Filter!\n"); + // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in // FPU raising the exception again. _clearfp(); @@ -65,54 +84,58 @@ extern "C" FPCW_API int RaiseFPException(void) printf("Error setting FPCW: %d\n", err); return -1; } - - printf("Passed\n"); } - } - __except(ExcepFilter(GetExceptionInformation())) - { - printf("Caught exception in Filter!\n"); - // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in - // FPU raising the exception again. - _clearfp(); - - // Reset FPCW - err = _controlfp_s(&fpcw, 0x1f, _MCW_EM); - if (err) - { - printf("Error setting FPCW: %d\n", err); - return -1; - } - } + return 100; +} +int TestUnderflow(void) +{ + unsigned int fpcw; // Underflow printf("Underflow: "); // Enable all FP exceptions - err = _controlfp_s(&fpcw, 0, _MCW_EM); + int err = _controlfp_s(&fpcw, 0, _MCW_EM); if (err) { printf("Error setting FPCW: %d\n", err); return -1; } - __try - { __try { - double a = 1e-40, b; - float y; - y = (float)a; - b = 2.0; - printf("Shouldn't execute!\n"); - return 98; + __try + { + double a = 1e-40, b; + float y; + y = (float)a; + b = 2.0; + printf("Shouldn't execute!\n"); + return 98; + } + __except((GetExceptionCode()==0xc0000093)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) + { + printf("Caught exception!\n"); + + // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in + // FPU raising the exception again. + _clearfp(); + + // Reset FPCW + err = _controlfp_s(&fpcw, 0x1f, _MCW_EM); + if (err) + { + printf("Error setting FPCW: %d\n", err); + return -1; + } + printf("Passed\n"); + } } - __except((GetExceptionCode()==0xc0000093)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) + __except(ExcepFilter(GetExceptionInformation())) { - printf("Caught exception!\n"); - + printf("Caught exception in Filter!\n"); // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in // FPU raising the exception again. _clearfp(); @@ -124,70 +147,60 @@ extern "C" FPCW_API int RaiseFPException(void) printf("Error setting FPCW: %d\n", err); return -1; } - printf("Passed\n"); } - } - __except(ExcepFilter(GetExceptionInformation())) - { - printf("Caught exception in Filter!\n"); - // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in - // FPU raising the exception again. - _clearfp(); - // Reset FPCW - err = _controlfp_s(&fpcw, 0x1f, _MCW_EM); - if (err) - { - printf("Error setting FPCW: %d\n", err); - return -1; - } - } + return 100; +} + +int TestOverflow(void) +{ + unsigned int fpcw; // Overflow printf("Overflow: "); // Enable all FP exceptions - err = _controlfp_s(&fpcw, 0, _MCW_EM); + int err = _controlfp_s(&fpcw, 0, _MCW_EM); if (err) { printf("Error setting FPCW: %d\n", err); return -1; } - __try - { __try { - double a = 1e+40, b; - float y; - y = (float)a; - b = 2.0; - printf("Shouldn't execute!\n"); - return 97; - } - __except((GetExceptionCode()==0xc0000091)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) - { - printf("Caught exception!\n"); - - // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in - // FPU raising the exception again. - _clearfp(); - - // Reset FPCW - err = _controlfp_s(&fpcw, 0x1f, _MCW_EM); - if (err) + __try { - printf("Error setting FPCW: %d\n", err); - return -1; + double a = 1e+40, b; + float y; + y = (float)a; + b = 2.0; + printf("Shouldn't execute!\n"); + return 97; + } + __except((GetExceptionCode()==0xc0000091)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) + { + printf("Caught exception!\n"); + + // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in + // FPU raising the exception again. + _clearfp(); + + // Reset FPCW + err = _controlfp_s(&fpcw, 0x1f, _MCW_EM); + if (err) + { + printf("Error setting FPCW: %d\n", err); + return -1; + } + printf("Passed\n"); } - printf("Passed\n"); } - } - __except(ExcepFilter(GetExceptionInformation())) - { - printf("Caught exception in Filter!\n"); + __except(ExcepFilter(GetExceptionInformation())) + { + printf("Caught exception in Filter!\n"); - // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in + // Clear FPSW else the "waiting" FPU instructions used in _controlfp_s will result in // FPU raising the exception again. _clearfp(); @@ -198,9 +211,26 @@ extern "C" FPCW_API int RaiseFPException(void) printf("Error setting FPCW: %d\n", err); return -1; } - } - + } return 100; } +extern "C" FPCW_API int RaiseFPException(void) +{ + int result = TestDivByZero(); + + if (result != 100) + { + return result; + } + + result = TestUnderflow(); + + if (result != 100) + { + return result; + } + + return TestOverflow(); +}