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