- Handle the load/store alignment of bitfields.
- Fix a bug in TypeConverter::ConvertRECORD.

It fixes the consumer-typeset test on ARM.

llvm-svn: 41057
diff --git a/llvm-gcc-4.0/gcc/llvm-convert.cpp b/llvm-gcc-4.0/gcc/llvm-convert.cpp
index 579e775..9c729e9 100644
--- a/llvm-gcc-4.0/gcc/llvm-convert.cpp
+++ b/llvm-gcc-4.0/gcc/llvm-convert.cpp
@@ -2478,9 +2478,9 @@
   LValue LV = EmitLV(exp);
   bool isVolatile = TREE_THIS_VOLATILE(exp);
   const Type *Ty = ConvertType(TREE_TYPE(exp));
+  unsigned Alignment = expr_align(exp) / 8;
   
   if (!LV.isBitfield()) {
-    unsigned Alignment = expr_align(exp) / 8;
     if (!DestLoc) {
       // Scalar value: emit a load.
       Value *Ptr = CastToType(Instruction::BitCast, LV.Ptr, 
@@ -2495,7 +2495,10 @@
     }
   } else {
     // This is a bitfield reference.
-    Value *Val = Builder.CreateLoad(LV.Ptr, isVolatile, "tmp");
+    LoadInst *LI = Builder.CreateLoad(LV.Ptr, isVolatile, "tmp");
+    LI->setAlignment(Alignment);
+
+    Value *Val = LI;
     unsigned ValSizeInBits = Val->getType()->getPrimitiveSizeInBits();
       
     assert(Val->getType()->isInteger() && "Invalid bitfield lvalue!");
@@ -2968,7 +2971,9 @@
 
   // Last case, this is a store to a bitfield, so we have to emit a 
   // read/modify/write sequence.
-  Value *OldVal = Builder.CreateLoad(LV.Ptr, isVolatile, "tmp");
+  LoadInst *LI = Builder.CreateLoad(LV.Ptr, isVolatile, "tmp");
+  LI->setAlignment(Alignment);
+  Value *OldVal = LI;
   
   // If the target is big-endian, invert the bit in the word.
   unsigned ValSizeInBits = TD.getTypeSize(OldVal->getType())*8;
@@ -2997,7 +3002,8 @@
   
   // Finally, merge the two together and store it.
   Value *Val = Builder.CreateOr(OldVal, RHS, "tmp");
-  Builder.CreateStore(Val, LV.Ptr, isVolatile);
+  StoreInst *SI = Builder.CreateStore(Val, LV.Ptr, isVolatile);
+  SI->setAlignment(Alignment);
   return RetVal;
 }
 
diff --git a/llvm-gcc-4.0/gcc/llvm-types.cpp b/llvm-gcc-4.0/gcc/llvm-types.cpp
index de3e91b..f63a84f 100644
--- a/llvm-gcc-4.0/gcc/llvm-types.cpp
+++ b/llvm-gcc-4.0/gcc/llvm-types.cpp
@@ -1700,6 +1700,10 @@
         unsigned DeclBitAlignment = Info->getTypeAlignment(DeclFieldTy)*8;
         
         FieldOffsetInBits &= ~(DeclBitAlignment-1ULL);
+        // When we fix the field alignment, we must restart the FieldNo search
+        // because the FieldOffsetInBits can be lower than it was in the
+        // previous iteration.
+        CurFieldNo = 0;
       }
       
       // Figure out if this field is zero bits wide, e.g. {} or [0 x int].  Do