[cfe-commits] r78429 - in /cfe/trunk: include/clang/AST/Expr.h lib/CodeGen/CGExprAgg.cpp lib/Sema/SemaExpr.cpp

Anders Carlsson andersca at mac.com
Fri Aug 7 16:22:37 PDT 2009


Author: andersca
Date: Fri Aug  7 18:22:37 2009
New Revision: 78429

URL: http://llvm.org/viewvc/llvm-project?rev=78429&view=rev
Log:
Add CK_ToUnion and use it for aggregate expression codegen.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=78429&r1=78428&r2=78429&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Aug  7 18:22:37 2009
@@ -1178,7 +1178,10 @@
     CK_DerivedToBase,
     
     /// CK_Dynamic - Dynamic cast.
-    CK_Dynamic
+    CK_Dynamic,
+    
+    /// CK_ToUnion - Cast to union (GCC extension).
+    CK_ToUnion
   };
   
 private:

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=78429&r1=78428&r2=78429&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Fri Aug  7 18:22:37 2009
@@ -86,8 +86,7 @@
   }
   
   // 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 @@
 //                            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 @@
     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");

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=78429&r1=78428&r2=78429&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Aug  7 18:22:37 2009
@@ -2990,6 +2990,7 @@
       // 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 @@
       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)





More information about the cfe-commits mailing list