[PATCH] Don't perform init-order checking for globals with no user-defined constructors.
Alexey Samsonov
samsonov at google.com
Thu Apr 4 04:01:21 PDT 2013
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D608.2.patch
Type: text/x-patch
Size: 1362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130404/7aec3722/attachment.bin>
More information about the cfe-commits
mailing list