/// - 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 {
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();
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) {