[cfe-commits] r41448 - /cfe/trunk/CodeGen/CGExprScalar.cpp
Chris Lattner
sabre at nondot.org
Sun Aug 26 09:52:28 PDT 2007
Author: lattner
Date: Sun Aug 26 11:52:28 2007
New Revision: 41448
URL: http://llvm.org/viewvc/llvm-project?rev=41448&view=rev
Log:
implement conversions of complex to bool.
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=41448&r1=41447&r2=41448&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Sun Aug 26 11:52:28 2007
@@ -293,9 +293,8 @@
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::
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);
}
More information about the cfe-commits
mailing list