hanchenye-llvm-project/clang/lib/Sema
Nico Weber b3a9978dc8 Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed().
clang currently calls MarkVTableUsed() for classes that get their virtual
methods called or that participate in a dynamic_cast. This is unnecessary,
since CodeGen only emits vtables when it generates constructor, destructor, and
vtt code. (*)

Note that Sema::MarkVTableUsed() doesn't cause the emission of a vtable.
Its main user-visible effect is that it instantiates virtual member functions
of template classes, to make sure that if codegen decides to write a vtable
all the entries in the vtable are defined.

While this shouldn't change the behavior of codegen (other than being faster),
it does make clang more permissive: virtual methods of templates (in particular
destructors) end up being instantiated less often. In particular, classes that
have members that are smart pointers to incomplete types will now get their
implicit virtual destructor instantiated less frequently. For example, this
used to not compile but does now compile:

    template <typename T> struct OwnPtr {
      ~OwnPtr() { static_assert((sizeof(T) > 0), "TypeMustBeComplete"); }
    };
    class ScriptLoader;
    struct Base { virtual ~Base(); };
    struct Sub : public Base {
      virtual void someFun() const {}
      OwnPtr<ScriptLoader> m_loader;
    };
    void f(Sub *s) { s->someFun(); }

The more permissive behavior matches both gcc (where this is not often
observable, since in practice most things with virtual methods have a key
function, and Sema::DefineUsedVTables() skips vtables for classes with key
functions) and cl (which is my motivation for this change) – this fixes
PR20337.  See this issue and the review thread for some discussions about
optimizations.

This is similar to r213109 in spirit. r225761 was a prerequisite for this
change.

Various tests relied on "a->f()" marking a's vtable as used (in the sema
sense), switch these to just construct a on the stack. This forces
instantiation of the implicit constructor, which will mark the vtable as used.

(*) The exception is -fapple-kext mode: In this mode, qualified calls to
virtual functions (`a->Base::f()`) still go through the vtable, and since the
vtable pointer off this doesn't point to Base's vtable, this needs to reference
Base's vtable directly. To keep this working, keep referencing the vtable for
virtual calls in apple kext mode.

llvm-svn: 227073
2015-01-26 06:23:36 +00:00
..
AnalysisBasedWarnings.cpp Update for LLVM API change to make Small(Ptr)Set::insert return pair<iterator, bool> as per the C++ standard's associative container concept. 2014-11-19 07:49:47 +00:00
AttributeList.cpp
CMakeLists.txt
CodeCompleteConsumer.cpp
DeclSpec.cpp [OpenCL] Generic address space has been added in OpenCL v2.0. 2014-11-26 14:10:06 +00:00
DelayedDiagnostic.cpp
IdentifierResolver.cpp
JumpDiagnostics.cpp Initial support for Win64 SEH IR emission 2015-01-22 01:36:17 +00:00
Makefile
MultiplexExternalSemaSource.cpp
Scope.cpp Initial support for Win64 SEH IR emission 2015-01-22 01:36:17 +00:00
ScopeInfo.cpp Objective-C ARC. Fixes a crash when checking for 'weak' propery 2014-11-21 21:12:11 +00:00
Sema.cpp Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
SemaAccess.cpp Don't assume friended C++ method decls have qualifiers 2014-12-17 23:40:46 +00:00
SemaAttr.cpp MS Compat: mark globals emitted in read-only sections const 2014-10-16 20:52:46 +00:00
SemaCUDA.cpp Consider calls from implict host device functions as valid in SemaCUDA. 2014-12-16 20:12:38 +00:00
SemaCXXScopeSpec.cpp Handle unscoped enumeration in nested name specifier. 2015-01-18 20:04:35 +00:00
SemaCast.cpp Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
SemaChecking.cpp [X86] Add immediate range checking to AVX512 integer comparision builtins. 2015-01-25 23:30:05 +00:00
SemaCodeComplete.cpp Sema: Formatting. No behavior change. 2015-01-25 17:00:47 +00:00
SemaConsumer.cpp
SemaDecl.cpp Revert "Sema: err_after_alias is unreachable, remove it" 2015-01-21 01:30:40 +00:00
SemaDeclAttr.cpp AST: Don't ignore alignas on EnumDecls when calculating alignment 2015-01-21 10:54:38 +00:00
SemaDeclCXX.cpp Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
SemaDeclObjC.cpp Objective-C: Tweak unavailability warning. 2014-12-27 07:09:37 +00:00
SemaExceptionSpec.cpp Delay checking overrides for exception specifications if the overridden 2014-11-22 03:09:05 +00:00
SemaExpr.cpp Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
SemaExprCXX.cpp Fix crash-on-invalid and name lookup when recovering from ~X::X() typo. 2015-01-15 00:48:52 +00:00
SemaExprMember.cpp [cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.py 2015-01-14 11:29:14 +00:00
SemaExprObjC.cpp Patch fixes PR21932 crash on invalid code. Using 2015-01-20 16:53:34 +00:00
SemaFixItUtils.cpp
SemaInit.cpp Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
SemaLambda.cpp DR1048: drop top-level cv-qualifiers when deducing the return type of a 2014-12-19 22:10:51 +00:00
SemaLookup.cpp Fix a case where delayed typo correction should have resolved an 2015-01-16 22:11:04 +00:00
SemaObjCProperty.cpp Suggest objc_method_family(none) for a property named -newFoo or similar. 2015-01-16 23:04:31 +00:00
SemaOpenMP.cpp [OPENMP] Fixed DSA processing for predetermined shared variables. 2015-01-20 07:03:46 +00:00
SemaOverload.cpp Remove an out-of-date and incorrect comment. 2015-01-22 01:15:51 +00:00
SemaPseudoObject.cpp
SemaStmt.cpp Rename RefersToCapturedVariable to RefersToEnclosingVariableOrCapture, NFC 2015-01-12 10:17:46 +00:00
SemaStmtAsm.cpp When reporting constraints that should be constant, the type doesn't 2015-01-22 21:01:00 +00:00
SemaStmtAttr.cpp Allow constant expressions in pragma loop hints. 2014-10-12 20:46:07 +00:00
SemaTemplate.cpp When checking the template argument list, use a copy of that list for changes 2015-01-24 02:48:32 +00:00
SemaTemplateDeduction.cpp Initial support for C++ parameter completion 2015-01-21 16:24:11 +00:00
SemaTemplateInstantiate.cpp PR22117: Fix a case where we would get confused about which function parameter 2015-01-09 01:19:56 +00:00
SemaTemplateInstantiateDecl.cpp Address review feedback from r215780: Use a flag insteda of the heap. No behavior change. 2015-01-18 01:50:35 +00:00
SemaTemplateVariadic.cpp Don't crash on an invalid trailing return type on a function before a '...' 2014-12-30 02:06:40 +00:00
SemaType.cpp Revert commit r226784. 2015-01-22 05:35:53 +00:00
TreeTransform.h Handle errors in lambda prototype instantiation correctly 2014-12-15 21:07:16 +00:00
TypeLocBuilder.cpp
TypeLocBuilder.h