reactos/modules/rostests/apitests/compiler/ms/eh/recursive_throw.cpp
Timo Kreuzer fe36f081c7
[COMPILER_APITEST] Add SEH tests from MS (#2435)
* [COMPILER_APITEST] Import MS EH/SEH tests

Taken from https://github.com/microsoft/compiler-tests

* [CRT] Add missing declaration of _longjmpex

* [COMPILER_APITEST] Add cmake build files for MS SEH test

It is built as a static library

* [COMPILER_APITEST] Fix GCC build of MS SEH tests

There are a number of hacks in there now. Also the volatile hacks should be separated and sent upstream.

* [COMPILER_APITEST] Fix x64 build of MS SEH tests

* [COMPILER_APITEST] Fix clang build of MS SEH tests

* [COMPILER_APITEST] Include MS SEH tests
2020-10-31 11:08:27 +01:00

78 lines
1.6 KiB
C++

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for
// full license information.
#include <stdio.h>
#include <windows.h>
#ifdef _M_CEE
#define MAX_REC 200
#else
#define MAX_REC 200
#endif
#define NLOOPS 10
#if defined(_M_SH) || defined(TRISC)
#undef MAX_REC
#define MAX_REC 3
#endif
#if defined(_M_AMD64)
#undef MAX_REC
#define MAX_REC 50
#endif
void foo(int level)
{
if(level < MAX_REC)
{
try
{
foo(level+1);
}
catch(int& throw_level)
{
//printf("Level %d catched level %d\n",level,throw_level);
throw_level = level;
//printf("Level %d throwing\n",level);
throw level;
}
}
else
{
printf("Level MAX_REC throwing.\n");
throw level;
}
}
int main(void)
{
int n;
LARGE_INTEGER freq,start,end;
#if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64)
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
#endif
//printf("Max Recursion level: %d\n", MAX_REC);
printf("N loops: %d\n", NLOOPS);
for(n=0;n<NLOOPS;n++)
{
try
{
foo(0);
}
catch(int& throw_level)
{
printf("main catched level %d\n",throw_level);
}
}
#if !defined(_M_AMD64) && !defined(_M_ARM) && !defined(_M_ARM64)
QueryPerformanceCounter(&end);
#endif
//printf("Exceptions per sec %lf\n",(double)(NLOOPS*MAX_REC)/((double)(end.QuadPart-start.QuadPart)/(double)freq.QuadPart));
}