summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-08-22 23:54:44 +0000
committerAnders Carlsson <andersca@mac.com>2009-08-22 23:54:44 +0000
commit3b0c5dcdd2fdbd4fe2ef9afaa08b58e6706d805b (patch)
tree8375dbbe2bc696c1ecc28eb08165411f1ae985d6 /clang/lib/CodeGen/CGExprConstant.cpp
parentd7923c6ed7ad6692656c7413d1e5653850b7b271 (diff)
downloadbcm5719-llvm-3b0c5dcdd2fdbd4fe2ef9afaa08b58e6706d805b.tar.gz
bcm5719-llvm-3b0c5dcdd2fdbd4fe2ef9afaa08b58e6706d805b.zip
Change the constant expression emitter to look at the cast kind for to-union casts.
llvm-svn: 79789
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 73576751f92..e67a747fa1b 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/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) {
OpenPOWER on IntegriCloud