mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
Add CK_ToUnion and use it for aggregate expression codegen.
llvm-svn: 78429
This commit is contained in:
@@ -1178,7 +1178,10 @@ public:
|
||||
CK_DerivedToBase,
|
||||
|
||||
/// CK_Dynamic - Dynamic cast.
|
||||
CK_Dynamic
|
||||
CK_Dynamic,
|
||||
|
||||
/// CK_ToUnion - Cast to union (GCC extension).
|
||||
CK_ToUnion
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -86,8 +86,7 @@ public:
|
||||
}
|
||||
|
||||
// Operators.
|
||||
void VisitCStyleCastExpr(CStyleCastExpr *E);
|
||||
void VisitImplicitCastExpr(ImplicitCastExpr *E);
|
||||
void VisitCastExpr(CastExpr *E);
|
||||
void VisitCallExpr(const CallExpr *E);
|
||||
void VisitStmtExpr(const StmtExpr *E);
|
||||
void VisitBinaryOperator(const BinaryOperator *BO);
|
||||
@@ -166,9 +165,9 @@ void AggExprEmitter::EmitFinalDestCopy(const Expr *E, LValue Src, bool Ignore) {
|
||||
// Visitor Methods
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void AggExprEmitter::VisitCStyleCastExpr(CStyleCastExpr *E) {
|
||||
// GCC union extension
|
||||
if (E->getSubExpr()->getType()->isScalarType()) {
|
||||
void AggExprEmitter::VisitCastExpr(CastExpr *E) {
|
||||
if (E->getCastKind() == CastExpr::CK_ToUnion) {
|
||||
// GCC union extension
|
||||
QualType PtrTy =
|
||||
CGF.getContext().getPointerType(E->getSubExpr()->getType());
|
||||
llvm::Value *CastPtr = Builder.CreateBitCast(DestPtr,
|
||||
@@ -178,10 +177,10 @@ void AggExprEmitter::VisitCStyleCastExpr(CStyleCastExpr *E) {
|
||||
return;
|
||||
}
|
||||
|
||||
Visit(E->getSubExpr());
|
||||
}
|
||||
|
||||
void AggExprEmitter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
|
||||
// FIXME: Remove the CK_Unknown check here.
|
||||
assert((E->getCastKind() == CastExpr::CK_NoOp ||
|
||||
E->getCastKind() == CastExpr::CK_Unknown) &&
|
||||
"Only no-op casts allowed!");
|
||||
assert(CGF.getContext().hasSameUnqualifiedType(E->getSubExpr()->getType(),
|
||||
E->getType()) &&
|
||||
"Implicit cast types must be compatible");
|
||||
|
||||
@@ -2990,6 +2990,7 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
|
||||
// FIXME: Check that the cast destination type is complete.
|
||||
Diag(TyR.getBegin(), diag::ext_typecheck_cast_nonscalar)
|
||||
<< castType << castExpr->getSourceRange();
|
||||
Kind = CastExpr::CK_NoOp;
|
||||
} else if (castType->isUnionType()) {
|
||||
// GCC cast to union extension
|
||||
RecordDecl *RD = castType->getAs<RecordType>()->getDecl();
|
||||
@@ -3006,6 +3007,7 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
|
||||
if (Field == FieldEnd)
|
||||
return Diag(TyR.getBegin(), diag::err_typecheck_cast_to_union_no_type)
|
||||
<< castExpr->getType() << castExpr->getSourceRange();
|
||||
Kind = CastExpr::CK_ToUnion;
|
||||
} else {
|
||||
// Reject any other conversions to non-scalar types.
|
||||
return Diag(TyR.getBegin(), diag::err_typecheck_cond_expect_scalar)
|
||||
|
||||
Reference in New Issue
Block a user