[cfe-commits] r45395 - in /cfe/trunk: CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h test/CodeGen/func-return-member.c

Christopher Lamb christopher.lamb at gmail.com
Fri Dec 28 21:02:43 PST 2007


Author: clamb
Date: Fri Dec 28 23:02:41 2007
New Revision: 45395

URL: http://llvm.org/viewvc/llvm-project?rev=45395&view=rev
Log:
Enable CodeGen for member expressions based on call expressions returning aggregate types. This enables expressions like 'foo().member.submember'.

Added:
    cfe/trunk/test/CodeGen/func-return-member.c
Modified:
    cfe/trunk/CodeGen/CGExpr.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Dec 28 23:02:41 2007
@@ -87,6 +87,7 @@
     return LValue::MakeAddr(llvm::UndefValue::get(Ty));
   }
 
+  case Expr::CallExprClass: return EmitCallExprLValue(cast<CallExpr>(E));
   case Expr::DeclRefExprClass: return EmitDeclRefLValue(cast<DeclRefExpr>(E));
   case Expr::ParenExprClass:return EmitLValue(cast<ParenExpr>(E)->getSubExpr());
   case Expr::PreDefinedExprClass:
@@ -455,6 +456,12 @@
   return EmitCallExpr(Callee, E);
 }
 
+LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) {
+  // Can only get l-value for call expression returning aggregate type
+  RValue RV = EmitCallExpr(E);
+  return LValue::MakeAddr(RV.getAggregateAddr());
+}
+
 RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, const CallExpr *E) {
   // The callee type will always be a pointer to function type, get the function
   // type.

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Fri Dec 28 23:02:41 2007
@@ -371,6 +371,9 @@
   /// is 'Ty'.
   void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
   void EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, QualType Ty);
+   
+  // Note: only availabe for agg return types
+  LValue EmitCallExprLValue(const CallExpr *E);
   
   LValue EmitDeclRefLValue(const DeclRefExpr *E);
   LValue EmitStringLiteralLValue(const StringLiteral *E);

Added: cfe/trunk/test/CodeGen/func-return-member.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/func-return-member.c?rev=45395&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/func-return-member.c (added)
+++ cfe/trunk/test/CodeGen/func-return-member.c Fri Dec 28 23:02:41 2007
@@ -0,0 +1,23 @@
+// RUN: clang -emit-llvm < %s 2>&1 | not grep 'cannot codegen this l-value expression yet'
+
+struct frk { float _Complex c; int x; };
+struct faz { struct frk f; };
+struct fuz { struct faz f; };
+
+extern struct fuz foo(void);
+
+int X;
+struct frk F;
+float _Complex C;
+
+void bar(void) {
+  X = foo().f.f.x;
+}
+
+void bun(void) {
+  F = foo().f.f;
+}
+
+void ban(void) {
+  C = foo().f.f.c;
+}





More information about the cfe-commits mailing list