diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-26 07:21:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-26 07:21:11 +0000 |
commit | cf289083ab007264fa3ea96d92f133339aee5d2d (patch) | |
tree | dfb67de0b037576c7e927f7c8f59683dfc8eeb6b /CodeGen | |
parent | 10b00cfe6422906b223724048b9b2123968d3baa (diff) |
implement conversions from complex to scalar types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41439 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen')
-rw-r--r-- | CodeGen/CGExprScalar.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index deaf0a89fe..ebe25c5a88 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -251,6 +251,8 @@ llvm::Value *ScalarExprEmitter::EmitScalarConversion(llvm::Value *Src, SrcType = SrcType.getCanonicalType(); DstType = DstType.getCanonicalType(); if (SrcType == DstType) return Src; + + if (DstType->isVoidType()) return 0; // Handle conversions to bool first, they are special: comparisons against 0. if (const BuiltinType *DestBT = dyn_cast<BuiltinType>(DstType)) @@ -367,13 +369,20 @@ Value *ScalarExprEmitter::EmitCastExpr(const Expr *E, QualType DestTy) { if (!CGF.hasAggregateLLVMType(E->getType())) { Value *Src = Visit(const_cast<Expr*>(E)); - // If the destination is void, just evaluate the source. - if (DestTy->isVoidType()) return 0; - // Use EmitScalarConversion to perform the conversion. return EmitScalarConversion(Src, E->getType(), DestTy); } + if (const ComplexType *CT = E->getType()->getAsComplexType()) { + // Emit the complex value, only keeping the real component. C99 6.3.1.7p2: + // "When a value of complex type is converted to a real type, the imaginary + // part of the complex value is discarded and the value of the real part is + // converted according to the conversion rules for the corresponding real + // type. + Value *Src = CGF.EmitComplexExpr(E).first; + return EmitScalarConversion(Src, CT->getElementType(), DestTy); + } + RValue Src = CGF.EmitAnyExpr(E); // If the destination is void, just evaluate the source. |