]> granicus.if.org Git - clang/commitdiff
Always deserialize from PCH file scoped variables with non trivial constructor/destru...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 27 Jul 2010 12:56:10 +0000 (12:56 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 27 Jul 2010 12:56:10 +0000 (12:56 +0000)
Fixes http://llvm.org/PR7692

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109501 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PCHWriterDecl.cpp
test/PCH/cxx-required-decls.cpp [new file with mode: 0644]
test/PCH/cxx-required-decls.h [new file with mode: 0644]

index abe2b30d1fe0a5f7775a0cddb7e4b355c4875052..06266d2282d5158e40afb4a28a06ed026983d9f8 100644 (file)
@@ -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 (file)
index 0000000..0e39ce3
--- /dev/null
@@ -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 (file)
index 0000000..f4fa79e
--- /dev/null
@@ -0,0 +1,7 @@
+// Header for PCH test cxx-required-decls.cpp
+
+struct S {
+  S();
+};
+
+static S globS;