From: Richard Smith Date: Mon, 1 Apr 2013 20:22:16 +0000 (+0000) Subject: Don't eagerly deserialize every templated function (and every static data X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f396ad9b1fa0c74c9db16a8158c3882c9db774e2;p=clang Don't eagerly deserialize every templated function (and every static data member inside a class template) when loading a PCH file or module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178496 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 6ac18a8d88..7245c03160 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -7673,7 +7673,15 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) { if (const VarDecl *VD = dyn_cast(D)) { if (!VD->isFileVarDecl()) return false; - } else if (!isa(D)) + } else if (const FunctionDecl *FD = dyn_cast(D)) { + // We never need to emit an uninstantiated function template. + if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) + return false; + } else + return false; + + // If this is a member of a class template, we do not need to emit it. + if (D->getDeclContext()->isDependentContext()) return false; // Weak references don't produce any output by themselves. diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp index ddebae4df2..58c4c177fd 100644 --- a/test/PCH/cxx-templates.cpp +++ b/test/PCH/cxx-templates.cpp @@ -5,7 +5,7 @@ // Test with pch. // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o - -// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s // expected-no-diagnostics diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h index 00631ddbfb..e672b0b387 100644 --- a/test/PCH/cxx-templates.h +++ b/test/PCH/cxx-templates.h @@ -259,3 +259,13 @@ void f() { template void f(); } + +template void doNotDeserialize() {} +template struct ContainsDoNotDeserialize { + static int doNotDeserialize; +}; +template struct ContainsDoNotDeserialize2 { + static void doNotDeserialize(); +}; +template int ContainsDoNotDeserialize::doNotDeserialize = 0; +template void ContainsDoNotDeserialize2::doNotDeserialize() {}