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