]> granicus.if.org Git - clang/commitdiff
implement conversions of complex to bool.
authorChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 16:52:28 +0000 (16:52 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 16:52:28 +0000 (16:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41448 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGExprScalar.cpp

index 70a44625f9cb81b735e6d8e7413a3f09e00289ed..1b25460d452c7b242103f522c42c101792e8f661 100644 (file)
@@ -293,9 +293,8 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
   if (DstType->isVoidType()) return 0;
 
   // Handle conversions to bool first, they are special: comparisons against 0.
-  if (const BuiltinType *DestBT = dyn_cast<BuiltinType>(DstType))
-    if (DestBT->getKind() == BuiltinType::Bool)
-      return EmitConversionToBool(Src, SrcType);
+  if (DstType->isBooleanType())
+    return EmitConversionToBool(Src, SrcType);
   
   const llvm::Type *DstTy = ConvertType(DstType);
 
@@ -351,11 +350,21 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
 Value *ScalarExprEmitter::
 EmitComplexToScalarConversion(CodeGenFunction::ComplexPairTy Src,
                               QualType SrcTy, QualType DstTy) {
+  // Get the source element type.
+  SrcTy = cast<ComplexType>(SrcTy.getCanonicalType())->getElementType();
+  
+  // Handle conversions to bool first, they are special: comparisons against 0.
+  if (DstTy->isBooleanType()) {
+    //  Complex != 0  -> (Real != 0) | (Imag != 0)
+    Src.first  = EmitScalarConversion(Src.first, SrcTy, DstTy);
+    Src.second = EmitScalarConversion(Src.second, SrcTy, DstTy);
+    return Builder.CreateOr(Src.first, Src.second, "tobool");
+  }
+  
   // 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. 
-  SrcTy = cast<ComplexType>(SrcTy.getCanonicalType())->getElementType();
   return EmitScalarConversion(Src.first, SrcTy, DstTy);
 }