[PATCH] MS inline asm: Allow __asm blocks to set a return value

Reid Kleckner rnk at google.com
Wed Sep 3 14:04:42 PDT 2014


Hi majnemer,

If control falls off the end of a function after an __asm block, MSVC
assumes that the inline assembly filled the EAX and possibly EDX
registers with an appropriate return value. This functionality is used
in inline functions returning 64-bit integers in system headers, so we
need some amount of compatibility.

This is implemented in Clang by adding extra output constraints to every
inline asm block, and storing the resulting output registers into the
return value slot. If we see an asm block somewhere in the function
body, we emit a normal epilogue instead of marking the end of the
function with a return type unreachable.

Normal returns in functions not using this functionality will overwrite
the return value slot, and in most cases LLVM should be able to
eliminate the dead stores.

Fixes PR17201.

http://reviews.llvm.org/D5177

Files:
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenCXX/ms-inline-asm-return.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5177.13224.patch
Type: text/x-patch
Size: 9557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140903/d6108b73/attachment.bin>


More information about the cfe-commits mailing list