Add a new flag and attributes to control static destructor registration
authorErik Pilkington <erik.pilkington@gmail.com>
Tue, 21 Aug 2018 17:24:06 +0000 (17:24 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Tue, 21 Aug 2018 17:24:06 +0000 (17:24 +0000)
commit5a559e64a919dfdbc9d97af2a3529a2c9f555230
tree6dbe891715fe23defb265c1df486e9f097ada5bb
parent7d1790868f289ca7831c2175463899dbe2bdd5e3
Add a new flag and attributes to control static destructor registration

This commit adds the flag -fno-c++-static-destructors and the attributes
[[clang::no_destroy]] and [[clang::always_destroy]]. no_destroy specifies that a
specific static or thread duration variable shouldn't have it's destructor
registered, and is the default in -fno-c++-static-destructors mode.
always_destroy is the opposite, and is the default in -fc++-static-destructors
mode.

A variable whose destructor is disabled (either because of
-fno-c++-static-destructors or [[clang::no_destroy]]) doesn't count as a use of
the destructor, so we don't do any access checking or mark it referenced. We
also don't emit -Wexit-time-destructors for these variables.

rdar://21734598

Differential revision: https://reviews.llvm.org/D50994

llvm-svn: 340306
18 files changed:
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CodeGenCXX/always_destroy.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/no_destroy.cpp [new file with mode: 0644]
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/SemaCXX/no_destroy.cpp [new file with mode: 0644]
clang/test/SemaCXX/warn-exit-time-destructors.cpp