From 46f93d021a1778442c1c4a53f0b94a68bfae3be5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 24 Aug 2007 21:20:17 +0000 Subject: [PATCH] implement codegen for real/imag. TODO: imag of non-complex. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41376 91177308-0d34-0410-b5e6-96231b3b80d8 --- CodeGen/CGExprScalar.cpp | 21 +++++++++++++++++++-- test/CodeGen/complex.c | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index bdaf1795de..c10e5106d8 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -147,7 +147,8 @@ public: } Value *EmitSizeAlignOf(QualType TypeToSize, QualType RetType, bool isSizeOf); - // FIXME: Real,Imag. + Value *VisitUnaryReal (const UnaryOperator *E); + Value *VisitUnaryImag (const UnaryOperator *E); Value *VisitUnaryExtension(const UnaryOperator *E) { return Visit(E->getSubExpr()); } @@ -363,7 +364,7 @@ Value *ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *E) { /// EmitSizeAlignOf - Return the size or alignment of the 'TypeToSize' type as /// an integer (RetType). Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize, - QualType RetType,bool isSizeOf){ + QualType RetType,bool isSizeOf){ /// FIXME: This doesn't handle VLAs yet! std::pair Info = CGF.getContext().getTypeInfo(TypeToSize, SourceLocation()); @@ -377,6 +378,22 @@ Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize, return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val)); } +Value *ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *E) { + Expr *Op = E->getSubExpr(); + if (Op->getType()->isComplexType()) + return CGF.EmitComplexExpr(Op).first; + return Visit(Op); +} +Value *ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *E) { + Expr *Op = E->getSubExpr(); + if (Op->getType()->isComplexType()) + return CGF.EmitComplexExpr(Op).second; + + // FIXME: does this evaluate the subexpr?? + return 0; // FIXME: Return zero of the right int/fp type. +} + + //===----------------------------------------------------------------------===// // Binary Operators //===----------------------------------------------------------------------===// diff --git a/test/CodeGen/complex.c b/test/CodeGen/complex.c index 3b5437c184..8a496ea425 100644 --- a/test/CodeGen/complex.c +++ b/test/CodeGen/complex.c @@ -26,4 +26,6 @@ void test3() { g1 = g1 - g2; g1 = g1 * g2; g1 = +-~g1; + + double Gr = __real g1; } -- 2.40.0