From: Chris Lattner Date: Fri, 4 Apr 2008 16:54:41 +0000 (+0000) Subject: Since isComplexType() no longer returns true for _Complex integers, the code X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b2dc287177394a8f73833e2ad4f7ca8cd6f22bb;p=clang Since isComplexType() no longer returns true for _Complex integers, the code generator needs to call isAnyComplexType(). This fixes PR1960. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49220 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index a3155c4efa..3fcd60e7b6 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -123,7 +123,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const BlockVarDecl &D) { if (!hasAggregateLLVMType(Init->getType())) { llvm::Value *V = EmitScalarExpr(Init); Builder.CreateStore(V, DeclPtr, D.getType().isVolatileQualified()); - } else if (Init->getType()->isComplexType()) { + } else if (Init->getType()->isAnyComplexType()) { EmitComplexExprIntoAddr(Init, DeclPtr, D.getType().isVolatileQualified()); } else { EmitAggExpr(Init, DeclPtr, D.getType().isVolatileQualified()); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index c80b6a7a8b..8175730171 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -37,7 +37,7 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(const llvm::Type *Ty, /// expression and compare the result against zero, returning an Int1Ty value. llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) { QualType BoolTy = getContext().BoolTy; - if (!E->getType()->isComplexType()) + if (!E->getType()->isAnyComplexType()) return EmitScalarConversion(EmitScalarExpr(E), E->getType(), BoolTy); return EmitComplexToScalarConversion(EmitComplexExpr(E), E->getType(),BoolTy); @@ -51,7 +51,7 @@ RValue CodeGenFunction::EmitAnyExpr(const Expr *E, llvm::Value *AggLoc, bool isAggLocVolatile) { if (!hasAggregateLLVMType(E->getType())) return RValue::get(EmitScalarExpr(E)); - else if (E->getType()->isComplexType()) + else if (E->getType()->isAnyComplexType()) return RValue::getComplex(EmitComplexExpr(E)); EmitAggExpr(E, AggLoc, isAggLocVolatile); @@ -620,7 +620,7 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, if (!hasAggregateLLVMType(ArgTy)) { // Scalar argument is passed by-value. Args.push_back(EmitScalarExpr(ArgExprs[i])); - } else if (ArgTy->isComplexType()) { + } else if (ArgTy->isAnyComplexType()) { // Make a temporary alloca to pass the argument. llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy)); EmitComplexExprIntoAddr(ArgExprs[i], DestMem, false); @@ -637,7 +637,7 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, CI->setCallingConv(F->getCallingConv()); if (CI->getType() != llvm::Type::VoidTy) CI->setName("call"); - else if (ResultType->isComplexType()) + else if (ResultType->isAnyComplexType()) return RValue::getComplex(LoadComplexFromAddr(Args[0], false)); else if (hasAggregateLLVMType(ResultType)) // Struct return. diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index f57c2ed881..1ff7372a09 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -95,7 +95,7 @@ public: //===----------------------------------------------------------------------===// void AggExprEmitter::EmitAggregateClear(llvm::Value *DestPtr, QualType Ty) { - assert(!Ty->isComplexType() && "Shouldn't happen for complex"); + assert(!Ty->isAnyComplexType() && "Shouldn't happen for complex"); // Aggregate assignment turns into llvm.memset. const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); @@ -121,7 +121,7 @@ void AggExprEmitter::EmitAggregateClear(llvm::Value *DestPtr, QualType Ty) { void AggExprEmitter::EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, QualType Ty) { - assert(!Ty->isComplexType() && "Shouldn't happen for complex"); + assert(!Ty->isAnyComplexType() && "Shouldn't happen for complex"); // Aggregate assignment turns into llvm.memcpy. const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp index e25ee9563a..df8d1b404e 100644 --- a/lib/CodeGen/CGExprComplex.cpp +++ b/lib/CodeGen/CGExprComplex.cpp @@ -267,7 +267,7 @@ ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val, ComplexPairTy ComplexExprEmitter::EmitCast(Expr *Op, QualType DestTy) { // Two cases here: cast from (complex to complex) and (scalar to complex). - if (Op->getType()->isComplexType()) + if (Op->getType()->isAnyComplexType()) return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy); // C99 6.3.1.7: When a value of real type is converted to a complex type, the @@ -506,7 +506,7 @@ ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) { /// EmitComplexExpr - Emit the computation of the specified expression of /// complex type, ignoring the result. ComplexPairTy CodeGenFunction::EmitComplexExpr(const Expr *E) { - assert(E && E->getType()->isComplexType() && + assert(E && E->getType()->isAnyComplexType() && "Invalid complex expression to emit"); return ComplexExprEmitter(*this).Visit(const_cast(E)); @@ -517,7 +517,7 @@ ComplexPairTy CodeGenFunction::EmitComplexExpr(const Expr *E) { void CodeGenFunction::EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, bool DestIsVolatile) { - assert(E && E->getType()->isComplexType() && + assert(E && E->getType()->isAnyComplexType() && "Invalid complex expression to emit"); ComplexExprEmitter Emitter(*this); ComplexPairTy Val = Emitter.Visit(const_cast(E)); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index a50e66660f..de138a1d6b 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -466,7 +466,7 @@ Value *ScalarExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) { if (!CGF.hasAggregateLLVMType(ArgTy)) { // Scalar argument is passed by-value. Args.push_back(CGF.EmitScalarExpr(ArgExpr)); - } else if (ArgTy->isComplexType()) { + } else if (ArgTy->isAnyComplexType()) { // Make a temporary alloca to pass the argument. llvm::Value *DestMem = CGF.CreateTempAlloca(ConvertType(ArgTy)); CGF.EmitComplexExprIntoAddr(ArgExpr, DestMem, false); @@ -559,7 +559,7 @@ Value *ScalarExprEmitter::EmitCastExpr(const Expr *E, QualType DestTy) { return EmitScalarConversion(Src, E->getType(), DestTy); } - if (E->getType()->isComplexType()) { + if (E->getType()->isAnyComplexType()) { // Handle cases where the source is a complex type. return EmitComplexToScalarConversion(CGF.EmitComplexExpr(E), E->getType(), DestTy); @@ -669,13 +669,13 @@ Value *ScalarExprEmitter::EmitSizeAlignOf(QualType TypeToSize, Value *ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *E) { Expr *Op = E->getSubExpr(); - if (Op->getType()->isComplexType()) + if (Op->getType()->isAnyComplexType()) return CGF.EmitComplexExpr(Op).first; return Visit(Op); } Value *ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *E) { Expr *Op = E->getSubExpr(); - if (Op->getType()->isComplexType()) + if (Op->getType()->isAnyComplexType()) return CGF.EmitComplexExpr(Op).second; // __imag on a scalar returns zero. Emit it the subexpr to ensure side @@ -894,7 +894,7 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,unsigned UICmpOpc, unsigned SICmpOpc, unsigned FCmpOpc) { Value *Result; QualType LHSTy = E->getLHS()->getType(); - if (!LHSTy->isComplexType()) { + if (!LHSTy->isAnyComplexType()) { Value *LHS = Visit(E->getLHS()); Value *RHS = Visit(E->getRHS()); @@ -1130,7 +1130,7 @@ Value *CodeGenFunction::EmitScalarConversion(Value *Src, QualType SrcTy, Value *CodeGenFunction::EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy) { - assert(SrcTy->isComplexType() && !hasAggregateLLVMType(DstTy) && + assert(SrcTy->isAnyComplexType() && !hasAggregateLLVMType(DstTy) && "Invalid complex -> scalar conversion"); return ScalarExprEmitter(*this).EmitComplexToScalarConversion(Src, SrcTy, DstTy); diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index df62e4aa1d..4a41a4962f 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -36,7 +36,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { if (const Expr *E = dyn_cast(S)) { if (!hasAggregateLLVMType(E->getType())) EmitScalarExpr(E); - else if (E->getType()->isComplexType()) + else if (E->getType()->isAnyComplexType()) EmitComplexExpr(E); else EmitAggExpr(E, 0, false); @@ -344,7 +344,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { Builder.CreateRet(llvm::UndefValue::get(RetTy)); } else if (!hasAggregateLLVMType(RV->getType())) { Builder.CreateRet(EmitScalarExpr(RV)); - } else if (RV->getType()->isComplexType()) { + } else if (RV->getType()->isAnyComplexType()) { llvm::Value *SRetPtr = CurFn->arg_begin(); EmitComplexExprIntoAddr(RV, SRetPtr, false); } else { diff --git a/test/CodeGen/complex.c b/test/CodeGen/complex.c index 0cc002bc6d..93e25cf459 100644 --- a/test/CodeGen/complex.c +++ b/test/CodeGen/complex.c @@ -1,4 +1,4 @@ -// RUN: clang -emit-llvm %s +// RUN: clang -emit-llvm < %s int main(void) { @@ -46,3 +46,8 @@ void t2() { (__imag__ cf) = 4.0; } +// PR1960 +void t3() { + __complex__ long long v = 2; +} +