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