diff options
-rw-r--r-- | lib/Frontend/PCHWriterDecl.cpp | 8 | ||||
-rw-r--r-- | test/PCH/cxx-required-decls.cpp | 8 | ||||
-rw-r--r-- | test/PCH/cxx-required-decls.h | 7 |
3 files changed, 23 insertions, 0 deletions
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<VarDecl>(D); + // Structs that have non-trivial constructors or destructors must be seen. + if (const RecordType *RT = VD->getType()->getAs<RecordType>()) { + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(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; |