diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-22 23:54:44 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-22 23:54:44 +0000 |
commit | 0086ccb1985f392ac688a19b35b300610db102e8 (patch) | |
tree | dc2f382be12887c2070eb024f7e238e6f44a763a /lib/CodeGen/CGExprConstant.cpp | |
parent | 27a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2 (diff) |
Change the constant expression emitter to look at the cast kind for to-union casts.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79789 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 73576751f9..e67a747fa1 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -378,11 +378,14 @@ public: } llvm::Constant *VisitCastExpr(CastExpr* E) { - // GCC cast to union extension - if (E->getType()->isUnionType()) { + switch (E->getCastKind()) { + case CastExpr::CK_ToUnion: { + // GCC cast to union extension + assert(E->getType()->isUnionType() && + "Destination type is not union type!"); const llvm::Type *Ty = ConvertType(E->getType()); Expr *SubExpr = E->getSubExpr(); - + llvm::Constant *C = CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF); if (!C) @@ -396,28 +399,30 @@ public: Types.push_back(C->getType()); unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(Ty); - + assert(CurSize <= TotalSize && "Union size mismatch!"); if (unsigned NumPadBytes = TotalSize - CurSize) { const llvm::Type *Ty = llvm::Type::getInt8Ty(VMContext); if (NumPadBytes > 1) Ty = llvm::ArrayType::get(Ty, NumPadBytes); - + Elts.push_back(llvm::Constant::getNullValue(Ty)); Types.push_back(Ty); } - - llvm::StructType* STy = llvm::StructType::get(C->getType()->getContext(), - Types, false); + + llvm::StructType* STy = + llvm::StructType::get(C->getType()->getContext(), Types, false); return llvm::ConstantStruct::get(STy, Elts); } - - // Explicit and implicit no-op casts - QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); - if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) { - return Visit(E->getSubExpr()); + default: { + // FIXME: This should be handled by the CK_NoOp cast kind. + // Explicit and implicit no-op casts + QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); + if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) + return Visit(E->getSubExpr()); + return 0; + } } - return 0; } llvm::Constant *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { |