[llvm-commits] [llvm-gcc-4.2] r62163 - in /llvm-gcc-4.2/trunk/gcc: llvm-convert.cpp llvm-internal.h

Duncan Sands baldrick at free.fr
Tue Jan 13 03:36:34 PST 2009


Author: baldrick
Date: Tue Jan 13 05:36:29 2009
New Revision: 62163

URL: http://llvm.org/viewvc/llvm-project?rev=62163&view=rev
Log:
Revert r62076 "Load / store alignments...": on
x86-64 linux it causes the compiler to crash on
the following tests:
  FrontendC/2004-05-07-VarArrays.c
  FrontendC/2007-03-01-VarSizeArrayIdx.c
  FrontendC/2007-03-27-ArrayCompatible.c
  FrontendC++/2005-02-20-BrokenReferenceTest.cpp
It also causes the compiler to crash during the
x86-32 Ada build due to trying to create an LValue
with an alignment of zero.  Finally, it is not at
all clear to me that this is the right approach
(see discussion on mailing list).

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-internal.h

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=62163&r1=62162&r2=62163&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Jan 13 05:36:29 2009
@@ -1150,18 +1150,9 @@
   case IMAGPART_EXPR: return EmitLV_XXXXPART_EXPR(exp, 1);
 
   // Constants.
-  case LABEL_DECL: {
-    Value *Ptr = TreeConstantToLLVM::EmitLV_LABEL_DECL(exp);
-    return LValue(Ptr, DECL_ALIGN(exp) / 8);
-  }
-  case COMPLEX_CST: {
-    Value *Ptr = TreeConstantToLLVM::EmitLV_COMPLEX_CST(exp);
-    return LValue(Ptr, TYPE_ALIGN(TREE_TYPE(exp)) / 8);
-  }
-  case STRING_CST: {
-    Value *Ptr = TreeConstantToLLVM::EmitLV_STRING_CST(exp);
-    return LValue(Ptr, TYPE_ALIGN(TREE_TYPE(exp)) / 8);
-  }
+  case LABEL_DECL:   return TreeConstantToLLVM::EmitLV_LABEL_DECL(exp);
+  case COMPLEX_CST:  return LValue(TreeConstantToLLVM::EmitLV_COMPLEX_CST(exp));
+  case STRING_CST:   return LValue(TreeConstantToLLVM::EmitLV_STRING_CST(exp));
 
   // Type Conversion.
   case VIEW_CONVERT_EXPR: return EmitLV_VIEW_CONVERT_EXPR(exp);
@@ -1174,11 +1165,9 @@
   case WITH_SIZE_EXPR:
     // The address is the address of the operand.
     return EmitLV(TREE_OPERAND(exp, 0));
-  case INDIRECT_REF: {
+  case INDIRECT_REF:
     // The lvalue is just the address.
-    tree Op = TREE_OPERAND(exp, 0);
-    return LValue(Emit(Op, 0), expr_align(Op) / 8);
-  }
+    return Emit(TREE_OPERAND(exp, 0), 0);
   }
 }
 
@@ -2301,7 +2290,7 @@
   LValue LV = EmitLV(exp);
   bool isVolatile = TREE_THIS_VOLATILE(exp);
   const Type *Ty = ConvertType(TREE_TYPE(exp));
-  unsigned Alignment = LV.getAlignment();
+  unsigned Alignment = expr_align(exp) / 8;
   if (TREE_CODE(exp) == COMPONENT_REF) 
     if (const StructType *STy = 
         dyn_cast<StructType>(ConvertType(TREE_TYPE(TREE_OPERAND(exp, 0)))))
@@ -2974,7 +2963,7 @@
 
   LValue LV = EmitLV(lhs);
   bool isVolatile = TREE_THIS_VOLATILE(lhs);
-  unsigned Alignment = LV.getAlignment();
+  unsigned Alignment = expr_align(lhs) / 8;
   if (TREE_CODE(lhs) == COMPONENT_REF) 
     if (const StructType *STy = 
         dyn_cast<StructType>(ConvertType(TREE_TYPE(TREE_OPERAND(lhs, 0)))))
@@ -3168,7 +3157,7 @@
       LValue LV = EmitLV(Op);
       assert(!LV.isBitfield() && "Expected an aggregate operand!");
       bool isVolatile = TREE_THIS_VOLATILE(Op);
-      unsigned Alignment = LV.getAlignment();
+      unsigned Alignment = expr_align(Op) / 8;
 
       EmitAggregateCopy(Target, MemRef(LV.Ptr, Alignment, isVolatile),
                         TREE_TYPE(exp));
@@ -5896,10 +5885,9 @@
   Value *Decl = DECL_LLVM(exp);
   if (Decl == 0) {
     if (errorcount || sorrycount) {
-      const Type *Ty = ConvertType(TREE_TYPE(exp));
-      const PointerType *PTy = PointerType::getUnqual(Ty);
-      LValue LV(ConstantPointerNull::get(PTy), 1);
-      return LV;
+      const PointerType *Ty =
+        PointerType::getUnqual(ConvertType(TREE_TYPE(exp)));
+      return ConstantPointerNull::get(Ty);
     }
     assert(0 && "INTERNAL ERROR: Referencing decl that hasn't been laid out");
     abort();
@@ -5936,13 +5924,7 @@
   // type void.
   if (Ty == Type::VoidTy) Ty = StructType::get(NULL, NULL);
   const PointerType *PTy = PointerType::getUnqual(Ty);
-  unsigned Alignment = Ty->isSized() ? TD.getABITypeAlignment(Ty) : 1;
-  if (DECL_ALIGN_UNIT(exp)) {
-    if (DECL_USER_ALIGN(exp) || Alignment < (unsigned)DECL_ALIGN_UNIT(exp))
-      Alignment = DECL_ALIGN_UNIT(exp);
-  }
-
-  return LValue(BitCastToType(Decl, PTy), Alignment);
+  return BitCastToType(Decl, PTy);
 }
 
 LValue TreeToLLVM::EmitLV_ARRAY_REF(tree exp) {
@@ -5950,23 +5932,22 @@
   // of ElementTy in the case of ARRAY_RANGE_REF.
 
   tree Array = TREE_OPERAND(exp, 0);
-  tree ArrayTreeType = TREE_TYPE(Array);
+  tree ArrayType = TREE_TYPE(Array);
   tree Index = TREE_OPERAND(exp, 1);
   tree IndexType = TREE_TYPE(Index);
-  tree ElementType = TREE_TYPE(ArrayTreeType);
+  tree ElementType = TREE_TYPE(ArrayType);
 
-  assert((TREE_CODE (ArrayTreeType) == ARRAY_TYPE ||
-          TREE_CODE (ArrayTreeType) == POINTER_TYPE ||
-          TREE_CODE (ArrayTreeType) == REFERENCE_TYPE ||
-          TREE_CODE (ArrayTreeType) == BLOCK_POINTER_TYPE) &&
+  assert((TREE_CODE (ArrayType) == ARRAY_TYPE ||
+          TREE_CODE (ArrayType) == POINTER_TYPE ||
+          TREE_CODE (ArrayType) == REFERENCE_TYPE ||
+          TREE_CODE (ArrayType) == BLOCK_POINTER_TYPE) &&
          "Unknown ARRAY_REF!");
 
   // As an LLVM extension, we allow ARRAY_REF with a pointer as the first
   // operand.  This construct maps directly to a getelementptr instruction.
   Value *ArrayAddr;
-  unsigned ArrayAlign;
 
-  if (TREE_CODE(ArrayTreeType) == ARRAY_TYPE) {
+  if (TREE_CODE(ArrayType) == ARRAY_TYPE) {
     // First subtract the lower bound, if any, in the type of the index.
     tree LowerBound = array_ref_low_bound(exp);
     if (!integer_zerop(LowerBound))
@@ -5975,10 +5956,8 @@
     LValue ArrayAddrLV = EmitLV(Array);
     assert(!ArrayAddrLV.isBitfield() && "Arrays cannot be bitfields!");
     ArrayAddr = ArrayAddrLV.Ptr;
-    ArrayAlign = ArrayAddrLV.Alignment;
   } else {
     ArrayAddr = Emit(Array, 0);
-    ArrayAlign = expr_align(ArrayTreeType) / 8;
   }
 
   Value *IndexVal = Emit(Index, 0);
@@ -5992,27 +5971,20 @@
     IndexVal = CastToSIntType(IndexVal, IntPtrTy);
 
   // If this is an index into an LLVM array, codegen as a GEP.
-  if (isArrayCompatible(ArrayTreeType)) {
+  if (isArrayCompatible(ArrayType)) {
     Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), IndexVal };
     Value *Ptr = Builder.CreateGEP(ArrayAddr, Idxs, Idxs + 2);
-    const Type *ATy = cast<PointerType>(ArrayAddr->getType())->getElementType();
-    const Type *ElementTy = cast<ArrayType>(ATy)->getElementType();
-    unsigned Alignment = MinAlign(ArrayAlign, TD.getTypePaddedSize(ElementTy));
-    return LValue(BitCastToType(Ptr,
-                           PointerType::getUnqual(ConvertType(TREE_TYPE(exp)))),
-                  Alignment);
+    return BitCastToType(Ptr,
+                         PointerType::getUnqual(ConvertType(TREE_TYPE(exp))));
   }
 
   // If we are indexing over a fixed-size type, just use a GEP.
-  if (isSequentialCompatible(ArrayTreeType)) {
-    const Type *ElementTy = ConvertType(ElementType);
-    const Type *PtrElementTy = PointerType::getUnqual(ElementTy);
+  if (isSequentialCompatible(ArrayType)) {
+    const Type *PtrElementTy = PointerType::getUnqual(ConvertType(ElementType));
     ArrayAddr = BitCastToType(ArrayAddr, PtrElementTy);
     Value *Ptr = Builder.CreateGEP(ArrayAddr, IndexVal);
-    unsigned Alignment = MinAlign(ArrayAlign, TD.getABITypeAlignment(ElementTy));
-    return LValue(BitCastToType(Ptr,
-                           PointerType::getUnqual(ConvertType(TREE_TYPE(exp)))),
-                  Alignment);
+    return BitCastToType(Ptr,
+                         PointerType::getUnqual(ConvertType(TREE_TYPE(exp))));
   }
 
   // Otherwise, just do raw, low-level pointer arithmetic.  FIXME: this could be
@@ -6020,21 +5992,14 @@
   //   float foo(int w, float A[][w], int g) { return A[g][0]; }
 
   ArrayAddr = BitCastToType(ArrayAddr, PointerType::getUnqual(Type::Int8Ty));
-  if (VOID_TYPE_P(TREE_TYPE(ArrayTreeType))) {
-    unsigned Alignment = MinAlign(ArrayAlign,
-                                  TD.getABITypeAlignment(Type::Int8Ty));
-    return LValue(Builder.CreateGEP(ArrayAddr, IndexVal), Alignment);
-  }
+  if (VOID_TYPE_P(TREE_TYPE(ArrayType)))
+    return Builder.CreateGEP(ArrayAddr, IndexVal);
 
   Value *TypeSize = Emit(array_ref_element_size(exp), 0);
   TypeSize = CastToUIntType(TypeSize, IntPtrTy);
   IndexVal = Builder.CreateMul(IndexVal, TypeSize);
   Value *Ptr = Builder.CreateGEP(ArrayAddr, IndexVal);
-  unsigned Alignment = MinAlign(ArrayAlign,
-                                cast<ConstantInt>(IndexVal)->getZExtValue());
-  return LValue(BitCastToType(Ptr,
-                           PointerType::getUnqual(ConvertType(TREE_TYPE(exp)))),
-                Alignment);
+  return BitCastToType(Ptr,PointerType::getUnqual(ConvertType(TREE_TYPE(exp))));
 }
 
 /// getFieldOffsetInBits - Return the offset (in bits) of a FIELD_DECL in a
@@ -6063,9 +6028,8 @@
 
 LValue TreeToLLVM::EmitLV_COMPONENT_REF(tree exp) {
   LValue StructAddrLV = EmitLV(TREE_OPERAND(exp, 0));
-  tree FieldDecl = TREE_OPERAND(exp, 1); 
-  unsigned LVAlign = DECL_PACKED(FieldDecl) ? 1 : StructAddrLV.Alignment;
- 
+  tree FieldDecl = TREE_OPERAND(exp, 1);
+
   assert((TREE_CODE(DECL_CONTEXT(FieldDecl)) == RECORD_TYPE ||
           TREE_CODE(DECL_CONTEXT(FieldDecl)) == UNION_TYPE  ||
           TREE_CODE(DECL_CONTEXT(FieldDecl)) == QUAL_UNION_TYPE));
@@ -6100,9 +6064,7 @@
     // the offset from BitStart.
     if (MemberIndex) {
       const StructLayout *SL = TD.getStructLayout(cast<StructType>(StructTy));
-      unsigned Offset = SL->getElementOffset(MemberIndex);
-      BitStart -= Offset * 8;
-      LVAlign = MinAlign(LVAlign, Offset);
+      BitStart -= SL->getElementOffset(MemberIndex) * 8;
     }
     
     // If the FIELD_DECL has an annotate attribute on it, emit it.
@@ -6188,7 +6150,6 @@
       Offset = Builder.CreateAdd(Offset,
         ConstantInt::get(Offset->getType(), ByteOffset));
       BitStart -= ByteOffset*8;
-      LVAlign = MinAlign(LVAlign, ByteOffset);
     }
 
     Value *Ptr = CastToType(Instruction::PtrToInt, StructAddrLV.Ptr, 
@@ -6260,7 +6221,6 @@
 
       // Compute the byte offset, and add it to the pointer.
       unsigned ByteOffset = NumAlignmentUnits*ByteAlignment;
-      LVAlign = MinAlign(LVAlign, ByteOffset);
 
       Constant *Offset = ConstantInt::get(TD.getIntPtrType(), ByteOffset);
       FieldPtr = CastToType(Instruction::PtrToInt, FieldPtr,
@@ -6282,18 +6242,17 @@
 
     // Okay, everything is good.  Return this as a bitfield if we can't
     // return it as a normal l-value. (e.g. "struct X { int X : 32 };" ).
-    // Conservatively return LValue with alignment 1.
     if (BitfieldSize != LLVMValueBitSize || BitStart != 0)
-      return LValue(FieldPtr, 1, BitStart, BitfieldSize);
+      return LValue(FieldPtr, BitStart, BitfieldSize);
   } else {
     // Make sure we return a pointer to the right type.
-    const Type *EltTy = ConvertType(TREE_TYPE(exp));
-    FieldPtr = BitCastToType(FieldPtr, PointerType::getUnqual(EltTy));
+    FieldPtr = BitCastToType(FieldPtr,
+                          PointerType::getUnqual(ConvertType(TREE_TYPE(exp))));
   }
   
   assert(BitStart == 0 &&
          "It's a bitfield reference or we didn't get to the field!");
-  return LValue(FieldPtr, LVAlign);
+  return LValue(FieldPtr);
 }
 
 LValue TreeToLLVM::EmitLV_BIT_FIELD_REF(tree exp) {
@@ -6325,28 +6284,17 @@
   }
   
   // If this is referring to the whole field, return the whole thing.
-  if (BitStart == 0 && BitSize == ValueSizeInBits) {
-    return LValue(BitCastToType(Ptr.Ptr, PointerType::getUnqual(ValTy)),
-                  Ptr.Alignment);
-  }
+  if (BitStart == 0 && BitSize == ValueSizeInBits)
+    return LValue(BitCastToType(Ptr.Ptr, PointerType::getUnqual(ValTy)));
   
-  return LValue(BitCastToType(Ptr.Ptr, PointerType::getUnqual(ValTy)), 1,
-                BitStart, BitSize);
+  return LValue(BitCastToType(Ptr.Ptr, PointerType::getUnqual(ValTy)), BitStart,
+                BitSize);
 }
 
 LValue TreeToLLVM::EmitLV_XXXXPART_EXPR(tree exp, unsigned Idx) {
   LValue Ptr = EmitLV(TREE_OPERAND(exp, 0));
-  assert(!Ptr.isBitfield() &&
-         "REALPART_EXPR / IMAGPART_EXPR operands cannot be bitfields!");
-  unsigned Alignment;
-  if (Idx == 0)
-    // REALPART alignment is same as the complex operand.
-    Alignment = Ptr.Alignment;
-  else
-    // IMAGPART alignment = MinAlign(Ptr.Alignment, sizeof field);
-    Alignment = MinAlign(Ptr.Alignment,
-                         TD.getTypePaddedSize(Ptr.Ptr->getType()));
-  return LValue(Builder.CreateStructGEP(Ptr.Ptr, Idx), Alignment);
+  assert(!Ptr.isBitfield() && "BIT_FIELD_REF operands cannot be bitfields!");
+  return LValue(Builder.CreateStructGEP(Ptr.Ptr, Idx));
 }
 
 LValue TreeToLLVM::EmitLV_VIEW_CONVERT_EXPR(tree exp) {
@@ -6362,30 +6310,24 @@
   } else {
     // If the input is a scalar, emit to a temporary.
     Value *Dest = CreateTemporary(ConvertType(TREE_TYPE(Op)));
-    StoreInst *S = Builder.CreateStore(Emit(Op, 0), Dest);
+    Builder.CreateStore(Emit(Op, 0), Dest);
     // The type is the type of the expression.
     Dest = BitCastToType(Dest,  
                          PointerType::getUnqual(ConvertType(TREE_TYPE(exp))));
-    return LValue(Dest, S->getAlignment());
+    return LValue(Dest);
   }
 }
 
 LValue TreeToLLVM::EmitLV_EXC_PTR_EXPR(tree exp) {
   CreateExceptionValues();
   // Cast the address pointer to the expected type.
-  unsigned Alignment = TD.getABITypeAlignment(cast<PointerType>(ExceptionValue->
-                                                  getType())->getElementType());
-  return LValue(BitCastToType(ExceptionValue,
-                              PointerType::getUnqual(ConvertType(TREE_TYPE(exp)))),
-                Alignment);
+  return BitCastToType(ExceptionValue,
+                       PointerType::getUnqual(ConvertType(TREE_TYPE(exp))));
 }
 
 LValue TreeToLLVM::EmitLV_FILTER_EXPR(tree exp) {
   CreateExceptionValues();
-  unsigned Alignment =
-    TD.getABITypeAlignment(cast<PointerType>(ExceptionSelectorValue->
-                                             getType())->getElementType());
-  return LValue(ExceptionSelectorValue, Alignment);
+  return ExceptionSelectorValue;
 }
 
 //===----------------------------------------------------------------------===//

Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=62163&r1=62162&r2=62163&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Tue Jan 13 05:36:29 2009
@@ -251,30 +251,23 @@
 };
 
 /// LValue - This struct represents an lvalue in the program.  In particular,
-/// the Ptr member indicates the memory that the lvalue lives in.  Alignment
-/// is the alignment of the memory (in bytes).If this is a bitfield reference,
-/// BitStart indicates the first bit in the memory that is part of the field
-/// and BitSize indicates the extent.
+/// the Ptr member indicates the memory that the lvalue lives in.  If this is
+/// a bitfield reference, BitStart indicates the first bit in the memory that
+/// is part of the field and BitSize indicates the extent.
 ///
 /// "LValue" is intended to be a light-weight object passed around by-value.
 struct LValue {
   Value *Ptr;
-  unsigned char Alignment;
   unsigned char BitStart;
   unsigned char BitSize;
   
-  LValue(Value *P, unsigned Align)
-    : Ptr(P), Alignment(Align), BitStart(255), BitSize(255) {}
-  LValue(Value *P, unsigned Align, unsigned BSt, unsigned BSi) 
-  : Ptr(P), Alignment(Align), BitStart(BSt), BitSize(BSi) {
+  LValue(Value *P) : Ptr(P), BitStart(255), BitSize(255) {}
+  LValue(Value *P, unsigned BSt, unsigned BSi)
+    : Ptr(P), BitStart(BSt), BitSize(BSi) {
       assert(BitStart == BSt && BitSize == BSi &&
              "Bit values larger than 256?");
-    }
-
-  unsigned getAlignment() const {
-    assert(Alignment && "LValue alignment cannot be zero!");
-    return Alignment;
   }
+
   bool isBitfield() const { return BitStart != 255; }
 };
 





More information about the llvm-commits mailing list