r178856 - Allow EmitConstantInit() to emit constant initializers for objects with trivial constructors and non-trivial destructors. Test that such objects are ignored by init-order checker.

Alexey Samsonov samsonov at google.com
Fri Apr 5 00:47:29 PDT 2013


Author: samsonov
Date: Fri Apr  5 02:47:28 2013
New Revision: 178856

URL: http://llvm.org/viewvc/llvm-project?rev=178856&view=rev
Log:
Allow EmitConstantInit() to emit constant initializers for objects with trivial constructors and non-trivial destructors. Test that such objects are ignored by init-order checker.

Added:
    cfe/trunk/test/CodeGen/sanitize-init-order.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=178856&r1=178855&r2=178856&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Apr  5 02:47:28 2013
@@ -1018,8 +1018,7 @@ llvm::Constant *CodeGenModule::EmitConst
       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());
       }
   }

Added: cfe/trunk/test/CodeGen/sanitize-init-order.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sanitize-init-order.cpp?rev=178856&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/sanitize-init-order.cpp (added)
+++ cfe/trunk/test/CodeGen/sanitize-init-order.cpp Fri Apr  5 02:47:28 2013
@@ -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





More information about the cfe-commits mailing list