[cfe-commits] r43525 - in /cfe/trunk: AST/Expr.cpp CodeGen/CGExpr.cpp test/CodeGen/complex.c
Chris Lattner
sabre at nondot.org
Tue Oct 30 15:53:42 PDT 2007
Author: lattner
Date: Tue Oct 30 17:53:42 2007
New Revision: 43525
URL: http://llvm.org/viewvc/llvm-project?rev=43525&view=rev
Log:
__real__ and __imag__ can be lvalues. Add support to ast and codegen for them.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/complex.c
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=43525&r1=43524&r2=43525&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Tue Oct 30 17:53:42 2007
@@ -278,6 +278,7 @@
/// - e->name
/// - *e, the type of e cannot be a function type
/// - string-constant
+/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension]
/// - reference type [C++ [expr]]
///
Expr::isLvalueResult Expr::isLvalue() const {
@@ -307,9 +308,13 @@
const MemberExpr *m = cast<MemberExpr>(this);
return m->isArrow() ? LV_Valid : m->getBase()->isLvalue();
}
- case UnaryOperatorClass: // C99 6.5.3p4
+ case UnaryOperatorClass:
if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
- return LV_Valid;
+ return LV_Valid; // C99 6.5.3p4
+
+ if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
+ cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag)
+ return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(); // GNU.
break;
case ParenExprClass: // C99 6.5.1p5
return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=43525&r1=43524&r2=43525&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Tue Oct 30 17:53:42 2007
@@ -283,9 +283,21 @@
if (E->getOpcode() == UnaryOperator::Extension)
return EmitLValue(E->getSubExpr());
- assert(E->getOpcode() == UnaryOperator::Deref &&
- "'*' is the only unary operator that produces an lvalue");
- return LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()));
+ switch (E->getOpcode()) {
+ default: assert(0 && "Unknown unary operator lvalue!");
+ case UnaryOperator::Deref:
+ return LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()));
+ case UnaryOperator::Real:
+ case UnaryOperator::Imag:
+ LValue LV = EmitLValue(E->getSubExpr());
+
+ llvm::Constant *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
+ llvm::Constant *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
+ E->getOpcode() == UnaryOperator::Imag);
+ llvm::Value *Ops[] = {Zero, Idx};
+ return LValue::MakeAddr(Builder.CreateGEP(LV.getAddress(), Ops, Ops+2,
+ "idx"));
+ }
}
LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) {
Modified: cfe/trunk/test/CodeGen/complex.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/complex.c?rev=43525&r1=43524&r2=43525&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/complex.c (original)
+++ cfe/trunk/test/CodeGen/complex.c Tue Oct 30 17:53:42 2007
@@ -37,3 +37,12 @@
g1 = g1 + D;
g1 = D + g1;
}
+
+void t1() {
+ (__real__ cf) = 4.0;
+}
+
+void t2() {
+ (__imag__ cf) = 4.0;
+}
+
More information about the cfe-commits
mailing list