From: Argyrios Kyrtzidis Date: Tue, 27 Jul 2010 12:56:10 +0000 (+0000) Subject: Always deserialize from PCH file scoped variables with non trivial constructor/destru... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90176d1ef0c3a8c4e87184920cc2ec65e1394d0a;p=clang Always deserialize from PCH file scoped variables with non trivial constructor/destructor. Fixes http://llvm.org/PR7692 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109501 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp index abe2b30d1f..06266d2282 100644 --- a/lib/Frontend/PCHWriterDecl.cpp +++ b/lib/Frontend/PCHWriterDecl.cpp @@ -1114,6 +1114,14 @@ static bool isRequiredDecl(const Decl *D, ASTContext &Context) { } else { const VarDecl *VD = cast(D); + // Structs that have non-trivial constructors or destructors must be seen. + if (const RecordType *RT = VD->getType()->getAs()) { + if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) { + if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor()) + return true; + } + } + // In C++, this doesn't need to be seen if it is marked "extern". if (Context.getLangOptions().CPlusPlus && !VD->getInit() && (VD->getStorageClass() == VarDecl::Extern || diff --git a/test/PCH/cxx-required-decls.cpp b/test/PCH/cxx-required-decls.cpp new file mode 100644 index 0000000000..0e39ce36fe --- /dev/null +++ b/test/PCH/cxx-required-decls.cpp @@ -0,0 +1,8 @@ +// Test this without pch. +// RUN: %clang_cc1 -include %S/cxx-required-decls.h %s -emit-llvm -o - | FileCheck %s + +// Test with pch. +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-required-decls.h +// RUN: %clang_cc1 -include-pch %t %s -emit-llvm -o - | FileCheck %s + +// CHECK: @_ZL5globS = internal global %struct.S zeroinitializer diff --git a/test/PCH/cxx-required-decls.h b/test/PCH/cxx-required-decls.h new file mode 100644 index 0000000000..f4fa79e4ee --- /dev/null +++ b/test/PCH/cxx-required-decls.h @@ -0,0 +1,7 @@ +// Header for PCH test cxx-required-decls.cpp + +struct S { + S(); +}; + +static S globS;