]> granicus.if.org Git - clang/commitdiff
Handle function calls that return aggregate expressions.
authorAnders Carlsson <andersca@mac.com>
Wed, 31 Oct 2007 22:04:46 +0000 (22:04 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 31 Oct 2007 22:04:46 +0000 (22:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43581 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprAgg.cpp
test/CodeGen/struct.c

index 160f491c5e836e1b5f89523ce232b3b23990d770..ea36225ba58279bdbf74d6b4d49f1bc8066c1ec4 100644 (file)
@@ -67,7 +67,7 @@ public:
   //  case Expr::UnaryOperatorClass:
   //  case Expr::ImplicitCastExprClass:
   //  case Expr::CastExprClass: 
-  //  case Expr::CallExprClass:
+  void VisitCallExpr(const CallExpr *E);
   void VisitStmtExpr(const StmtExpr *E);
   void VisitBinaryOperator(const BinaryOperator *BO);
   void VisitBinAssign(const BinaryOperator *E);
@@ -132,6 +132,19 @@ void AggExprEmitter::EmitAggLoadOfLValue(const Expr *E) {
 //                            Visitor Methods
 //===----------------------------------------------------------------------===//
 
+void AggExprEmitter::VisitCallExpr(const CallExpr *E)
+{
+  RValue RV = CGF.EmitCallExpr(E);
+  assert(RV.isAggregate() && "Return value must be aggregate value!");
+  
+  // If the result is ignored, don't copy from the value.
+  if (DestPtr == 0)
+    // FIXME: If the source is volatile, we must read from it.
+    return;
+  
+  EmitAggregateCopy(DestPtr, RV.getAggregateAddr(), E->getType());
+}
+
 void AggExprEmitter::VisitStmtExpr(const StmtExpr *E) {
   CGF.EmitCompoundStmt(*E->getSubStmt(), true, DestPtr, VolatileDest);
 }
index 443fc33ccb30f89ca70ba6af0145932d0a740332..83ac4d219511bb8aa2fcc5767dbe890fc34b79eb 100644 (file)
@@ -63,3 +63,17 @@ void f4() {
 void f5() {
   (f3())->d1 = 42;
 }
+
+/* Function calls */
+typedef struct {
+  int location;
+  int length;
+} range;
+
+extern range f6();
+void f7()
+{
+       range r = f6();
+}
+
+