]> granicus.if.org Git - clang/commitdiff
Don't eagerly deserialize every templated function (and every static data
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 1 Apr 2013 20:22:16 +0000 (20:22 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 1 Apr 2013 20:22:16 +0000 (20:22 +0000)
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

lib/AST/ASTContext.cpp
test/PCH/cxx-templates.cpp
test/PCH/cxx-templates.h

index 6ac18a8d88eea93f674c09a5b8c2138f371c13b9..7245c0316082972dcda84cf77e5b4eecd04ee5d4 100644 (file)
@@ -7673,7 +7673,15 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
     if (!VD->isFileVarDecl())
       return false;
-  } else if (!isa<FunctionDecl>(D))
+  } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(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.
index ddebae4df24ac6455cf7d6a3a6fe0fda568f5291..58c4c177fd215fef5c244082955032489d7d9aba 100644 (file)
@@ -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
 
index 00631ddbfb937b55f15b10af4f2bbaf61f789102..e672b0b38733ece9b0e7b2ea9cb5900f239f2225 100644 (file)
@@ -259,3 +259,13 @@ void f() {
 
 template void f<int>();
 }
+
+template<typename T> void doNotDeserialize() {}
+template<typename T> struct ContainsDoNotDeserialize {
+  static int doNotDeserialize;
+};
+template<typename T> struct ContainsDoNotDeserialize2 {
+  static void doNotDeserialize();
+};
+template<typename T> int ContainsDoNotDeserialize<T>::doNotDeserialize = 0;
+template<typename T> void ContainsDoNotDeserialize2<T>::doNotDeserialize() {}