From fe029c9c69a2feb0c41f0c42330048ba957dcedb Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Thu, 20 Feb 2014 20:20:26 +0000 Subject: [PATCH] [PSEH2_TEST] Add another test for non-volatile values. Note that PSEH does NOT work like real SEH here, but this is expected and can not be fixed without special compiler support. Do NEVER DO this kind of stuff inside SEH blocks! Use volatile variables in this case. svn path=/trunk/; revision=62268 --- rostests/tests/pseh2/psehtest.c | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/rostests/tests/pseh2/psehtest.c b/rostests/tests/pseh2/psehtest.c index eb46701e77a..66cd6e5620e 100644 --- a/rostests/tests/pseh2/psehtest.c +++ b/rostests/tests/pseh2/psehtest.c @@ -2439,6 +2439,54 @@ DEFINE_TEST(test_unvolatile_2) return (val == 3) || (val == 4) || (val == 5); } +DEFINE_TEST(test_unvolatile_3) +{ + int register val1 = 0, val2 = 0; + + _SEH2_TRY + { + val1 = 1; + + _SEH2_TRY + { + val2 = 1; + *((char*)0xc0000000) = 0; + val2 = 2; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + val2 |= 4; + } + _SEH2_END; + + val1 = 2; + *((int*)0xc0000000) = 1; + val1 = 3; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + val1 = val1 * val2; + } + _SEH2_END; + + /* The expected case */ + if ((val1 == 10) && (val2 == 5)) + return TRUE; + + /* The compiler can optimize away "val1 = 1" and "val1 = 2" and + only use the last "val1 = 3", in this case val1 is still 0 + when the outer exception handler kicks in */ + if ((val1 == 0) && (val2 == 5)) + return TRUE; + + /* Same as above, but this time val2 optimized away */ + if (((val1 == 8) && (val2 == 4)) || + ((val1 == 0) && (val2 == 4))) + return TRUE; + + return FALSE; +} + DEFINE_TEST(test_finally_goto) { volatile int val = 0; @@ -2765,6 +2813,7 @@ void testsuite_syntax(void) USE_TEST(test_unvolatile), USE_TEST(test_unvolatile_2), + USE_TEST(test_unvolatile_3), USE_TEST(test_finally_goto), USE_TEST(test_nested_exception), USE_TEST(test_PSEH3_bug), -- 2.17.1