5

Visual C++ has an intrinsic function called _AddressOfReturnAddress which returns the address of the current function's return address on the stack.

Note that this is not the same as _ReturnAddress, which only returns a copy of the return address.

Is there any equivalent for _AddressOfReturnAddress in Clang/LLVM?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user541686
  • 205,094
  • 128
  • 528
  • 886

2 Answers2

5

As rustyx pointed out, Clang/LLVM (and GCC) provides __builtin_return_address() which is equivalent to _ReturnAddress(). Clang/LLVM also provides __builtin_frame_address() which (depending on the particulars of your ABI, architecture, etc.) may be somewhat analogous to _AddressOfReturnAddress().

As an example, the following code...

std::cout<< ((int64_t) __builtin_return_address(0)) << ' '
         << ((int64_t) __builtin_frame_address (0)) << ' '
         <<*((int64_t*)__builtin_frame_address (0)+1)<<'\n';

...prints the following on an OS X machine.

140735807202733 140734600362944 140735807202733
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ceilingcat
  • 671
  • 7
  • 11
  • +1 not that I need it or have the chance to check it anymore, but I think this was probably the solution I ended up going with too. Thanks! – user541686 Aug 06 '16 at 07:52
2

No. LLVM IR does not provide an intrinsic for this.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael Spencer
  • 1,029
  • 9
  • 18
  • There is no equivalent for `_AddressOfReturnAddress` but there is `__builtin_return_address` which is the equivalent for `_ReturnAddress`. – rustyx Oct 02 '15 at 11:25