llvm-project/clang/test
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
..
ARCMT Objective-C moderinzer [qoi], add space on rhs when needed when 2015-01-23 21:58:46 +00:00
ASTMerge
Analysis PR6037 2015-01-19 01:44:02 +00:00
CXX Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
CodeCompletion
CodeGen [X86] Add AVX512F integer comparision intrinsics to header file. 2015-01-25 23:30:07 +00:00
CodeGenCUDA IR: Make metadata typeless in assembly, clang side 2014-12-15 19:10:08 +00:00
CodeGenCXX Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
CodeGenObjC IR: Move MDLocation into place (clang testcases) 2015-01-14 22:28:03 +00:00
CodeGenObjCXX Emit DeferredDeclsToEmit in a DFS order. 2015-01-22 00:24:57 +00:00
CodeGenOpenCL Re-apply "r226548 - Introduce SPIR calling conventions" reverted in r226558. 2015-01-20 11:20:41 +00:00
Coverage clang/test/Coverage/html-diagnostics.c: Use find(1) to avoid globbing. 2014-11-04 13:05:10 +00:00
CoverageMapping InstrProf: Avoid creating profile names for symbols in system headers 2015-01-22 02:17:23 +00:00
Driver Allows Clang to use LLVM's fixes-x18 option 2015-01-25 23:17:48 +00:00
FixIt PR21969: Improve diagnostics for a conversion function that has any pieces of a 2014-12-19 02:07:47 +00:00
Format Revert "clang/test/Driver/crash-report.c: This requires rewriter for -frewrite-includes. [PR20321]" 2014-07-16 15:12:48 +00:00
Frontend Frontend: Fix SourceColumnMap assertion failure on non-ascii characters. 2015-01-08 13:19:07 +00:00
Headers Add more feature flags to the x86 instrinsic test. 2014-12-27 06:59:44 +00:00
Index Sema: require a complete type before lookup. 2015-01-25 08:47:59 +00:00
Integration
Layout PR6037 2015-01-19 01:44:02 +00:00
Lexer Add driver flags -ftrigraphs, -fno-trigraphs. 2014-12-23 22:32:37 +00:00
Misc When checking the template argument list, use a copy of that list for changes 2015-01-24 02:48:32 +00:00
Modules [modules] Sometimes we can deserialize a class member but not have yet 2015-01-24 01:07:20 +00:00
OpenMP Support ‘omp for’ with static chunked schedule kind. 2015-01-22 08:49:35 +00:00
PCH Don't invent a '$auto-x-y' name for auto types in generic lambdas. This is no 2015-01-09 00:59:40 +00:00
Parser Update error message text. 2015-01-18 19:05:48 +00:00
Preprocessor [Mips] Fix type of 64-bit integer in case of MIPS N64 ABI 2015-01-22 23:16:48 +00:00
Profile InstrProf: Don't emit counter increments in dead code 2015-01-09 01:46:40 +00:00
Rewriter Objective-C modern rewriter. Patch to fix a rewriting bug 2014-10-28 23:46:58 +00:00
Sema Make the ?: precedence warning handle pointers to the left of ? 2015-01-22 22:11:56 +00:00
SemaCUDA Consider calls from implict host device functions as valid in SemaCUDA. 2014-12-16 20:12:38 +00:00
SemaCXX Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
SemaObjC Fix crashes on missing @interface for category 2015-01-20 20:41:36 +00:00
SemaObjCXX Update error message text. 2015-01-18 19:05:48 +00:00
SemaOpenCL Workaround attribute ordering issue with kernel only attributes 2014-12-05 18:03:58 +00:00
SemaTemplate Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed(). 2015-01-26 06:23:36 +00:00
TableGen
Tooling Remove "REQUIRES:shell" from tests. They work for me. 2014-11-04 13:41:33 +00:00
Unit Let test/Unit/lit.cfg add config.shlibdir to $PATH on DLL platforms like cygming. 2014-07-04 05:11:55 +00:00
VFS IR: Make metadata typeless in assembly, clang side 2014-12-15 19:10:08 +00:00
.clang-format
CMakeLists.txt Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00
Makefile Fix makefile for debuginfo-tests execution. 2014-10-17 23:50:47 +00:00
TestRunner.sh
cxx-sections.data
lit.cfg Reorganize test/Modules: 2015-01-22 23:07:47 +00:00
lit.site.cfg.in Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00
make_test_dirs.pl