Refactor some code and implement support for global destructors for static variables.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78507 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 44e8b44..aac79e9 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3227,7 +3227,7 @@
         if (!Constructor)
           Var->setInvalidDecl();
         else { 
-          if (!RD->hasTrivialConstructor())
+          if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor())
             InitializeVarWithConstructor(Var, Constructor, InitType, 0, 0);
           FinalizeVarWithDestructor(Var, InitType);
         }