]> granicus.if.org Git - clang/commitdiff
Allow EmitConstantInit() to emit constant initializers for objects with trivial const...
authorAlexey Samsonov <samsonov@google.com>
Fri, 5 Apr 2013 07:47:28 +0000 (07:47 +0000)
committerAlexey Samsonov <samsonov@google.com>
Fri, 5 Apr 2013 07:47:28 +0000 (07:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178856 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGen/sanitize-init-order.cpp [new file with mode: 0644]

index e3e5d66605107c4bac2b145940e27200724c51d6..faaf6468f1e3ef6b725885ef5113f0e93b2234a9 100644 (file)
@@ -1018,8 +1018,7 @@ llvm::Constant *CodeGenModule::EmitConstantInit(const VarDecl &D,
       if (const CXXConstructExpr *E =
           dyn_cast_or_null<CXXConstructExpr>(D.getInit())) {
         const CXXConstructorDecl *CD = E->getConstructor();
-        if (CD->isTrivial() && CD->isDefaultConstructor() &&
-            Ty->getAsCXXRecordDecl()->hasTrivialDestructor())
+        if (CD->isTrivial() && CD->isDefaultConstructor())
           return EmitNullConstant(D.getType());
       }
   }
diff --git a/test/CodeGen/sanitize-init-order.cpp b/test/CodeGen/sanitize-init-order.cpp
new file mode 100644 (file)
index 0000000..3e94620
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsanitize=address,init-order -emit-llvm -o - %s | FileCheck %s
+
+struct PODStruct {
+  int x;
+};
+PODStruct s1;
+
+struct PODWithDtor {
+  ~PODWithDtor() { }
+  int x;
+};
+PODWithDtor s2;
+
+struct PODWithCtorAndDtor {
+  PODWithCtorAndDtor() { }
+  ~PODWithCtorAndDtor() { }
+  int x;
+};
+PODWithCtorAndDtor s3;
+
+// Check that ASan init-order checking ignores structs with trivial default
+// constructor.
+// CHECK: !llvm.asan.dynamically_initialized_globals = !{[[GLOB:![0-9]+]]}
+// CHECK: [[GLOB]] = metadata !{%struct.PODWithCtorAndDtor