Change EmitConstantInit() function to allow constant initializers for objects
  with non-trivial destructors.

Hi kcc, rsmith,

http://llvm-reviews.chandlerc.com/D608

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D608?vs=1474&id=1503#toc

Files:
  lib/CodeGen/CGExprConstant.cpp
  test/CodeGen/sanitize-init-order.cpp

Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -1018,8 +1018,7 @@
       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());
       }
   }
Index: test/CodeGen/sanitize-init-order.cpp
===================================================================
--- /dev/null
+++ test/CodeGen/sanitize-init-order.cpp
@@ -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
Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -1018,8 +1018,7 @@
       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());
       }
   }
Index: test/CodeGen/sanitize-init-order.cpp
===================================================================
--- /dev/null
+++ test/CodeGen/sanitize-init-order.cpp
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to