]> granicus.if.org Git - clang/commitdiff
Simplify code by using the new getAggregateElement method that got added
authorChris Lattner <sabre@nondot.org>
Mon, 30 Jan 2012 06:20:36 +0000 (06:20 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 30 Jan 2012 06:20:36 +0000 (06:20 +0000)
recently.  This also conveniently gets clang ready for a change about to
land in mainline.

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

lib/CodeGen/CGExpr.cpp

index 0e19a4015af0a21ccdbaec17c86584415ef62c0c..3dd5cb9ba96691e4a287b9793d61defb7272a315 100644 (file)
@@ -511,10 +511,8 @@ CodeGenFunction::EmitReferenceBindingToExpr(const Expr *E,
 /// input field number being accessed.
 unsigned CodeGenFunction::getAccessedFieldNo(unsigned Idx,
                                              const llvm::Constant *Elts) {
-  if (isa<llvm::ConstantAggregateZero>(Elts))
-    return 0;
-
-  return cast<llvm::ConstantInt>(Elts->getOperand(Idx))->getZExtValue();
+  return cast<llvm::ConstantInt>(Elts->getAggregateElement(Idx))
+      ->getZExtValue();
 }
 
 void CodeGenFunction::EmitCheck(llvm::Value *Address, unsigned Size) {
@@ -1779,12 +1777,8 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
   llvm::Constant *BaseElts = Base.getExtVectorElts();
   SmallVector<llvm::Constant *, 4> CElts;
 
-  for (unsigned i = 0, e = Indices.size(); i != e; ++i) {
-    if (isa<llvm::ConstantAggregateZero>(BaseElts))
-      CElts.push_back(llvm::ConstantInt::get(Int32Ty, 0));
-    else
-      CElts.push_back(cast<llvm::Constant>(BaseElts->getOperand(Indices[i])));
-  }
+  for (unsigned i = 0, e = Indices.size(); i != e; ++i)
+    CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
   llvm::Constant *CV = llvm::ConstantVector::get(CElts);
   return LValue::MakeExtVectorElt(Base.getExtVectorAddr(), CV, type);
 }