[cfe-commits] r41439 - /cfe/trunk/CodeGen/CGExprScalar.cpp

Chris Lattner sabre at nondot.org
Sun Aug 26 00:21:13 PDT 2007


Author: lattner
Date: Sun Aug 26 02:21:11 2007
New Revision: 41439

URL: http://llvm.org/viewvc/llvm-project?rev=41439&view=rev
Log:
implement conversions from complex to scalar types.

Modified:
    cfe/trunk/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=41439&r1=41438&r2=41439&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Sun Aug 26 02:21:11 2007
@@ -251,6 +251,8 @@
   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 @@
   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.





More information about the cfe-commits mailing list