]> granicus.if.org Git - clang/commit
Do not register incompatible C++ destructors with __cxa_atexit
authorDerek Schuff <dschuff@google.com>
Tue, 10 May 2016 17:44:46 +0000 (17:44 +0000)
committerDerek Schuff <dschuff@google.com>
Tue, 10 May 2016 17:44:46 +0000 (17:44 +0000)
commitfa210fcce69fc84ec5cf86caf46202d6049c2636
tree44206dd396ed4ea6bbe727c4d11de54e1e37c04a
parente0b839eb21bc1498fe70466ccde63443ffb40623
Do not register incompatible C++ destructors with __cxa_atexit

Summary:
For a static object with a nontrivial destructor, clang generates an
initializer function (__cxx_global_var_init) which registers that
object's destructor using __cxa_atexit. However some ABIs (ARM,
WebAssembly) use destructors that return 'this' instead of having void
return (which does not match the signature of function pointers passed
to __cxa_atexit). This results in undefined behavior when the destructors are
called. All the calling conventions I know of on ARM can tolerate this,
but WebAssembly requires the signatures of indirect calls to match the
called function.

This patch disables that direct registration of destructors for ABIs
that have this-returning destructors.

Subscribers: aemerson, jfb, cfe-commits, dschuff

Differential Revision: http://reviews.llvm.org/D19275

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269085 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGDeclCXX.cpp
test/CodeGenCXX/runtimecc.cpp
test/CodeGenCXX/static-destructor.cpp [new file with mode: 0644]