]> granicus.if.org Git - clang/commitdiff
Minor work related to removing the assumption that value initialization
authorEli Friedman <eli.friedman@gmail.com>
Mon, 13 Apr 2009 21:47:26 +0000 (21:47 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 13 Apr 2009 21:47:26 +0000 (21:47 +0000)
implies an all-zero bit pattern.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68994 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprConstant.cpp
lib/CodeGen/CodeGenModule.h

index 3b1580cc136a6516d7f7a0f5e09d45d44b433035..acca396c0b077390fbd20e2ea4c2e753bf6e8a54 100644 (file)
@@ -312,6 +312,7 @@ void AggExprEmitter::EmitNullInitializationToLValue(LValue LV, QualType T) {
     // Otherwise, just memset the whole thing to zero.  This is legal
     // because in LLVM, all default initializers are guaranteed to have a
     // bit pattern of all zeros.
+    // FIXME: That isn't true for member pointers!
     // There's a potential optimization opportunity in combining
     // memsets; that would be easy for arrays, but relatively
     // difficult for structures with the current code.
index 2373ad64e92395c5a68e09ab0c030b394c0b1b4d..d7c6457ff8fd69e1657abb4bae19ffda04e6e432 100644 (file)
@@ -102,6 +102,7 @@ public:
     }
 
     // Initialize remaining array elements.
+    // FIXME: This doesn't handle member pointers correctly!
     for (; i < NumElements; ++i)
       Elts.push_back(llvm::Constant::getNullValue(ElemTy));
 
@@ -187,6 +188,7 @@ public:
     std::vector<llvm::Constant*> Elts;
 
     // Initialize the whole structure to zero.
+    // FIXME: This doesn't handle member pointers correctly!
     for (unsigned i = 0; i < SType->getNumElements(); ++i) {
       const llvm::Type *FieldTy = SType->getElementType(i);
       Elts.push_back(llvm::Constant::getNullValue(FieldTy));
@@ -255,11 +257,6 @@ public:
   llvm::Constant *EmitUnionInitialization(InitListExpr *ILE) {
     const llvm::Type *Ty = ConvertType(ILE->getType());
 
-    // If this is an empty initializer list, we value-initialize the
-    // union.
-    if (ILE->getNumInits() == 0)
-      return llvm::Constant::getNullValue(Ty);
-
     FieldDecl* curField = ILE->getInitializedFieldInUnion();
     if (!curField) {
       // There's no field to initialize, so value-initialize the union.
@@ -287,8 +284,14 @@ public:
       return llvm::ConstantArray::get(RetTy, Elts);
     }
 
-    Expr *Init = ILE->getInit(0);
-    return EmitUnion(CGM.EmitConstantExpr(Init, Init->getType(), CGF), Ty);
+    llvm::Constant *InitElem;
+    if (ILE->getNumInits() > 0) {
+      Expr *Init = ILE->getInit(0);
+      InitElem = CGM.EmitConstantExpr(Init, Init->getType(), CGF);
+    } else {
+      InitElem = CGM.EmitNullConstant(curField->getType());
+    }
+    return EmitUnion(InitElem, Ty);
   }
 
   llvm::Constant *EmitVectorInitialization(InitListExpr *ILE) {
@@ -318,8 +321,7 @@ public:
   }
   
   llvm::Constant *VisitImplicitValueInitExpr(ImplicitValueInitExpr* E) {
-    const llvm::Type* RetTy = CGM.getTypes().ConvertType(E->getType());
-    return llvm::Constant::getNullValue(RetTy);
+    return CGM.EmitNullConstant(E->getType());
   }
     
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
@@ -329,8 +331,7 @@ public:
         Expr *Init = ILE->getInit(0);
         return CGM.EmitConstantExpr(Init, Init->getType(), CGF);
       }
-      const llvm::Type* RetTy = CGM.getTypes().ConvertType(ILE->getType());
-      return llvm::Constant::getNullValue(RetTy);
+      return CGM.EmitNullConstant(ILE->getType());
     }
     
     if (ILE->getType()->isArrayType())
@@ -590,3 +591,9 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
   }
   return C;
 }
+
+llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
+  // Always return an LLVM null constant for now; this will change when we
+  // get support for IRGen of member pointers.
+  return llvm::Constant::getNullValue(getTypes().ConvertType(T));
+}
index 71cfb6409803f1b981cd875f3612e1b0b8472b0f..a1e2efc439180bdaefa93ccfcc748d243f8fae68 100644 (file)
@@ -259,6 +259,11 @@ public:
   llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
                                    CodeGenFunction *CGF = 0);
 
+  /// EmitNullConstant - Return the result of value-initializing the given
+  /// type, i.e. a null expression of the given type.  This is usually,
+  /// but not always, an LLVM null constant.
+  llvm::Constant *EmitNullConstant(QualType T);
+
   llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
                                    const AnnotateAttr *AA, unsigned LineNo);