]> granicus.if.org Git - clang/commitdiff
When explicitly building a temporary object (CXXTemporaryObjectExpr),
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 20:36:09 +0000 (20:36 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 20:36:09 +0000 (20:36 +0000)
keep track of whether we need to zero-initialize storage prior to
calling its constructor. Previously, we were only tracking this when
implicitly constructing the object (a CXXConstructExpr).

Fixes Boost's value-initialization tests, which means that the
Boost.Config library now passes all of its tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102461 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
lib/AST/ExprCXX.cpp
lib/Sema/SemaInit.cpp
test/CodeGenCXX/value-init.cpp

index d66642c1ad61fe5e3a7f6bd8da25a355aa045d8a..d26efa7296c925bd4be69311c73351720b435ac9 100644 (file)
@@ -784,7 +784,8 @@ public:
   CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
                          QualType writtenTy, SourceLocation tyBeginLoc,
                          Expr **Args,unsigned NumArgs,
-                         SourceLocation rParenLoc);
+                         SourceLocation rParenLoc,
+                         bool ZeroInitialization = false);
 
   ~CXXTemporaryObjectExpr() { }
 
index c394e476f81c450f98e50f70f89b66bcb9742124..592d887d31076be0f492d873e8e199630c87477a 100644 (file)
@@ -459,9 +459,10 @@ CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
                                                SourceLocation tyBeginLoc,
                                                Expr **Args,
                                                unsigned NumArgs,
-                                               SourceLocation rParenLoc)
+                                               SourceLocation rParenLoc,
+                                               bool ZeroInitialization)
   : CXXConstructExpr(C, CXXTemporaryObjectExprClass, writtenTy, tyBeginLoc,
-                     Cons, false, Args, NumArgs),
+                     Cons, false, Args, NumArgs, ZeroInitialization),
   TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {
 }
 
index 1caa94bf81c64a97f3b18e765b52774753ae0d93..4678822413d69ebc71d187ec9f9d440bbd6437c8 100644 (file)
@@ -3745,7 +3745,8 @@ InitializationSequence::Perform(Sema &S,
                                                             Kind.getLocation(),
                                                                  Exprs, 
                                                                  NumExprs,
-                                                Kind.getParenRange().getEnd()));
+                                                Kind.getParenRange().getEnd(),
+                                             ConstructorInitRequiresZeroInit));
       } else
         CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
                                           Constructor, 
index 37891bd6af67ea7425cd533cf89b48f065e1c103..35be159aac9d4e20fd59d4049ecc4c0afde5b872 100644 (file)
@@ -23,3 +23,29 @@ void test_value_init() {
   C c = { 17 } ;
   // CHECK: call void @_ZN1CD1Ev
 }
+
+enum enum_type { negative_number = -1, magic_number = 42 };
+
+class enum_holder
+{
+  enum_type m_enum;
+
+public:
+  enum_holder() : m_enum(magic_number) { }
+};
+
+struct enum_holder_and_int
+{
+  enum_holder e;
+  int i;
+};
+
+// CHECK: _Z24test_enum_holder_and_intv()
+void test_enum_holder_and_int() {
+  // CHECK: alloca
+  // CHECK-NEXT: bitcast
+  // CHECK-NEXT: call void @llvm.memset
+  // CHECK-NEXT: call void @_ZN19enum_holder_and_intC1Ev
+  enum_holder_and_int();
+  // CHECK-NEXT: ret void
+}