[cfe-commits] r84694 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/call-arg-zero-temp.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Oct 20 16:29:05 PDT 2009


Author: fjahanian
Date: Tue Oct 20 18:29:04 2009
New Revision: 84694

URL: http://llvm.org/viewvc/llvm-project?rev=84694&view=rev
Log:
Code-gen for CXXZeroInitValueExpr AST passed
as argument to a function call. Removes a FIXME.

Added:
    cfe/trunk/test/CodeGenCXX/call-arg-zero-temp.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=84694&r1=84693&r2=84694&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Oct 20 18:29:04 2009
@@ -566,10 +566,6 @@
       assert(!ClassDecl->hasUserDeclaredCopyConstructor() &&
              "EmitCXXConstructorCall - user declared copy constructor");
       const Expr *E = (*ArgBeg);
-      // FIXME. This may not be correct. But till now, we were skipping
-      // code gen of trivial copy constructors regardless of their arguments.
-      if (isa<CXXZeroInitValueExpr>(E))
-        return;
       QualType Ty = E->getType();
       llvm::Value *Src = EmitLValue(E).getAddress();
       EmitAggregateCopy(This, Src, Ty);

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=84694&r1=84693&r2=84694&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Oct 20 18:29:04 2009
@@ -303,6 +303,8 @@
   case Expr::CXXReinterpretCastExprClass:
   case Expr::CXXConstCastExprClass:
     return EmitCastLValue(cast<CastExpr>(E));
+  case Expr::CXXZeroInitValueExprClass:
+    return EmitNullInitializationLValue(cast<CXXZeroInitValueExpr>(E));
   }
 }
 
@@ -1313,6 +1315,18 @@
   }
 }
 
+LValue CodeGenFunction::EmitNullInitializationLValue(
+                                              const CXXZeroInitValueExpr *E) {
+  QualType Ty = E->getType();
+  const llvm::Type *LTy = ConvertTypeForMem(Ty);
+  llvm::AllocaInst *Alloc = CreateTempAlloca(LTy);
+  unsigned Align = getContext().getTypeAlign(Ty)/8;
+  Alloc->setAlignment(Align);
+  LValue lvalue = LValue::MakeAddr(Alloc, Qualifiers());
+  EmitMemSetToZero(lvalue.getAddress(), Ty);
+  return lvalue;
+}
+
 //===--------------------------------------------------------------------===//
 //                             Expression Emission
 //===--------------------------------------------------------------------===//

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=84694&r1=84693&r2=84694&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Oct 20 18:29:04 2009
@@ -817,7 +817,8 @@
   LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
   LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
   LValue EmitCastLValue(const CastExpr *E);
-
+  LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E);
+  
   llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
                               const ObjCIvarDecl *Ivar);
   LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,

Added: cfe/trunk/test/CodeGenCXX/call-arg-zero-temp.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/call-arg-zero-temp.cpp?rev=84694&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/call-arg-zero-temp.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/call-arg-zero-temp.cpp Tue Oct 20 18:29:04 2009
@@ -0,0 +1,23 @@
+// RUN: clang-cc -triple x86_64-apple-darwin -S %s -o %t-64.s &&
+// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
+// RUN: clang-cc -triple i386-apple-darwin -S %s -o %t-32.s &&
+// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s &&
+// RUN: true
+
+
+extern "C" int printf(...);
+
+struct obj{ int a; float b; double d; };
+
+void foo(obj o) {
+  printf("%d  %f  %f\n", o.a, o.b, o.d);
+}
+
+int main() {
+  obj o = obj();
+  foo(obj());
+}
+
+// CHECK-LP64: call     __Z3foo3obj
+
+// CHECK-LP32: call     __Z3foo3obj





More information about the cfe-commits mailing list