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
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp
index bdaf179..c10e510 100644
--- a/CodeGen/CGExprScalar.cpp
+++ b/CodeGen/CGExprScalar.cpp
@@ -147,7 +147,8 @@
}
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 @@
/// 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<uint64_t, unsigned> Info =
CGF.getContext().getTypeInfo(TypeToSize, SourceLocation());
@@ -377,6 +378,22 @@
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 3b5437c..8a496ea 100644
--- a/test/CodeGen/complex.c
+++ b/test/CodeGen/complex.c
@@ -26,4 +26,6 @@
g1 = g1 - g2;
g1 = g1 * g2;
g1 = +-~g1;
+
+ double Gr = __real g1;
}