From: Alexey Samsonov Date: Fri, 5 Apr 2013 07:47:28 +0000 (+0000) Subject: Allow EmitConstantInit() to emit constant initializers for objects with trivial const... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50f9de5d893694a7e46ba655ec9fce5dfeae9362;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178856 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index e3e5d66605..faaf6468f1 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1018,8 +1018,7 @@ llvm::Constant *CodeGenModule::EmitConstantInit(const VarDecl &D, if (const CXXConstructExpr *E = dyn_cast_or_null(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 index 0000000000..3e94620193 --- /dev/null +++ b/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