1 //
2 // This tests that we can call functions implemented using shared pointers
3 // from an API vending itself as returning raw pointers, because both are
4 // ABI compatible.
5 //
6 // In this TU, SharedPtr<T> is just T*, since USE_SHARED_PTR is not defined.
7 //
8 
9 #include <darwintest.h>
10 #include "abi_helper.h"
11 
12 // Receive a raw pointer from a function that actually returns a smart pointer
13 T_DECL(abi_caller_raw, "intrusive_shared_ptr.abi.caller.raw", T_META_TAG_VM_PREFERRED) {
14 	T obj{10};
15 	T* expected = &obj;
16 	T* result = return_shared_as_raw(expected);
17 	CHECK(result == expected);
18 
19 	// Sometimes the test above passes even though it should fail, if the
20 	// right address happens to be on the stack in the right location. This
21 	// can happen if abi.caller.smart is run just before this test. This
22 	// second test makes sure it fails when it should.
23 	CHECK(result->i == 10);
24 }
25