2 * Copyright (c) 2013 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
7 #include "native_client/tests/toolchain/eh_separate_files.h"
9 #include "native_client/tests/toolchain/eh_helper.h"
11 // Test that even with the non-stable exception handling PNaCl feature
12 // turned on, we generate the right calling conventions for
13 // portable (LE32) PNaCl bitcode. Otherwise, this is like eh_catch_many.cc.
15 // Declare the functions from the file2 as if it was pass-by-value.
16 // However, the definition in file2 will actually be pass-by-pointer,
17 // because that is what PNaCl expands it into.
19 // We need extern "C" since the prototypes aren't going to match.
21 extern __attribute__((noinline))
22 struct Var return_a_struct(int32_t set_fields_to);
24 extern __attribute__((noinline))
25 struct Var call_and_return(struct Var v);
27 extern __attribute__((noinline))
28 void call_with_struct(int32_t expected_values, struct Var v);
30 // file2 will call us back with a pointer, but we call it by-value.
31 extern __attribute__((noinline))
32 void call_with_callback(void (*fp)(struct Var* v), struct Var set_fields_to);
38 ~A() { next_step(10); }
45 ~B() { next_step(12);}
57 void my_callback(struct Var* v) {
66 int32_t kExpected = (1 << 20) - 1;
67 struct Var v = return_a_struct(kExpected);
68 if (v.type != kExpected
69 && v.value.as_double != (double)(kExpected)) {
70 printf("ERROR: return_a_struct mismatch: %d vs %d and %f vs %f\n",
71 v.type, kExpected, v.value.as_double, (double)kExpected);
75 v = call_and_return(v);
77 call_with_struct(kExpected, v);
78 // Also test callbacks.
79 call_with_callback(&my_callback, v);
80 if (global_v.type != kExpected
81 && global_v.value.as_double != (double)(kExpected)) {
82 printf("ERROR: callback mismatch: %d vs %d and %f vs %f\n",
83 global_v.type, kExpected,
84 global_v.value.as_double, (double)kExpected);