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