aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/try-catch-9.mm
blob: f79f52fbb9ac111c7cea329b54f7b94b8237ebd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Check that local variables that get modified inside the @try
   block survive until the @catch block is reached.  */
/* Developed by Ziemowit Laski <zlaski@apple.com>.  */

/* { dg-do run } */
/* { dg-xfail-if "PR23616" { *-*-* } { "*" } { "" } } */
/* { dg-prune-output ".*internal compiler error.*" } */
/* { dg-options "-fobjc-exceptions -O2" } */

#include <objc/Object.h>
#include <stdlib.h>
#include <stdio.h>

int gi1 = 9, gi2 = 19;
float gf1 = 9.0, gf2 = 19.0;
id obj2 = nil;

void foo (int arg1, float *arg2)
{
  int *pi = &gi1;
  float *pf = &gf1;
  id obj1 = nil;
  int local1 = 45, local2 = 47;
  float local3 = 3.0, local4 = 4.0;
  register int local5 = 15;
  static float local6 = 16.0;

  @try {
    local1 = 123;
    local2 = 345;
    local3 = 5.0;
    local4 = 6.0;
    local5 = 17;
    local6 = 18.0;
    pi = &gi2;
    pf = &gf2;
    obj2 = obj1 = [Object new];
    arg1 = 17;
    arg2 = &gf2;
    
    @throw [Object new];
  }
  @catch (Object *obj) {
   if (local1 != 123 || local2 != 345 || local3 != 5.0
       || local4 != 6.0 || local5 != 17 || local6 != 18.0) {
     printf("Abort 1\n");
     abort();
   }
   if (pi != &gi2 || pf != &gf2) {
     printf("Abort 2\n");
     abort();
   }
   if (!obj1 || obj1 != obj2) {
     printf("Abort 3\n");
     abort();
   }
   if (arg1 != 17 || arg2 != &gf2) {
     printf("Abort 4\n");
     abort();
   }
  }
}

int main(void) {
  foo(15, &gf1);
  return 0;
}