[cfe-commits] r68994 - in /cfe/trunk/lib/CodeGen: CGExprAgg.cpp CGExprConstant.cpp CodeGenModule.h

Eli Friedman eli.friedman at gmail.com
Mon Apr 13 14:47:26 PDT 2009


Author: efriedma
Date: Mon Apr 13 16:47:26 2009
New Revision: 68994

URL: http://llvm.org/viewvc/llvm-project?rev=68994&view=rev
Log:
Minor work related to removing the assumption that value initialization 
implies an all-zero bit pattern.


Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Mon Apr 13 16:47:26 2009
@@ -312,6 +312,7 @@
     // 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.

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Mon Apr 13 16:47:26 2009
@@ -102,6 +102,7 @@
     }
 
     // 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 @@
     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 @@
   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 @@
       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 @@
   }
   
   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 @@
         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 @@
   }
   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));
+}

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=68994&r1=68993&r2=68994&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Apr 13 16:47:26 2009
@@ -259,6 +259,11 @@
   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);
 





More information about the cfe-commits mailing list