[cfe-commits] r79789 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Anders Carlsson andersca at mac.com
Sat Aug 22 16:54:44 PDT 2009


Author: andersca
Date: Sat Aug 22 18:54:44 2009
New Revision: 79789

URL: http://llvm.org/viewvc/llvm-project?rev=79789&view=rev
Log:
Change the constant expression emitter to look at the cast kind for to-union casts.

Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Aug 22 18:54:44 2009
@@ -378,11 +378,14 @@
   }
   
   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 @@
       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) {





More information about the cfe-commits mailing list