[cfe-commits] r102461 - in /cfe/trunk: include/clang/AST/ExprCXX.h lib/AST/ExprCXX.cpp lib/Sema/SemaInit.cpp test/CodeGenCXX/value-init.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 27 13:36:09 PDT 2010


Author: dgregor
Date: Tue Apr 27 15:36:09 2010
New Revision: 102461

URL: http://llvm.org/viewvc/llvm-project?rev=102461&view=rev
Log:
When explicitly building a temporary object (CXXTemporaryObjectExpr),
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.

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

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=102461&r1=102460&r2=102461&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Apr 27 15:36:09 2010
@@ -784,7 +784,8 @@
   CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
                          QualType writtenTy, SourceLocation tyBeginLoc,
                          Expr **Args,unsigned NumArgs,
-                         SourceLocation rParenLoc);
+                         SourceLocation rParenLoc,
+                         bool ZeroInitialization = false);
 
   ~CXXTemporaryObjectExpr() { }
 

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=102461&r1=102460&r2=102461&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Apr 27 15:36:09 2010
@@ -459,9 +459,10 @@
                                                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) {
 }
 

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=102461&r1=102460&r2=102461&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Apr 27 15:36:09 2010
@@ -3745,7 +3745,8 @@
                                                             Kind.getLocation(),
                                                                  Exprs, 
                                                                  NumExprs,
-                                                Kind.getParenRange().getEnd()));
+                                                Kind.getParenRange().getEnd(),
+                                             ConstructorInitRequiresZeroInit));
       } else
         CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
                                           Constructor, 

Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=102461&r1=102460&r2=102461&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Tue Apr 27 15:36:09 2010
@@ -23,3 +23,29 @@
   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
+}





More information about the cfe-commits mailing list