[llvm-commits] [llvm-gcc-4.2] r65634 - /llvm-gcc-4.2/trunk/gcc/llvm-types.cpp

Duncan Sands baldrick at free.fr
Fri Feb 27 08:45:54 PST 2009


Author: baldrick
Date: Fri Feb 27 10:45:52 2009
New Revision: 65634

URL: http://llvm.org/viewvc/llvm-project?rev=65634&view=rev
Log:
Turn variable length arrays such as "char A[n]" into
[0 x i8] rather than i8.  Not only does this seem
more logical, but it also means that, in the case of
variable sized Ada types, the LLVM type will never
be larger than the smallest possible version of the
LLVM type, which has some theoretical importance
(though doesn't seem to matter much in practice).

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-types.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=65634&r1=65633&r2=65634&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Fri Feb 27 10:45:52 2009
@@ -906,9 +906,9 @@
     }
 
     // This handles cases like "int A[n]" which have a runtime constant
-    // number of elements, but is a compile-time variable.  Since these are
-    // variable sized, we just represent them as the element themself.
-    return TypeDB.setType(type, ConvertType(TREE_TYPE(type)));
+    // number of elements, but is a compile-time variable.  Since these
+    // are variable sized, we represent them as A[0].
+    return TypeDB.setType(type, ArrayType::get(ConvertType(TREE_TYPE(type)),0));
   }
   case OFFSET_TYPE:
     // Handle OFFSET_TYPE specially.  This is used for pointers to members,
@@ -2120,6 +2120,7 @@
         TREE_CODE(DECL_FIELD_OFFSET(Field)) == INTEGER_CST) {
       uint64_t FieldOffsetInBits = getFieldOffsetInBits(Field);
       tree FieldType = getDeclaredType(Field);
+      const Type *FieldTy = ConvertType(FieldType);
 
       // If this is a bitfield, we may want to adjust the FieldOffsetInBits to
       // produce safe code.  In particular, bitfields will be loaded/stored as
@@ -2127,7 +2128,6 @@
       // them.  As such, we need to respect the alignment of the declared type.
       if (isBitfield(Field)) {
         // If this is a bitfield, the declared type must be an integral type.
-        const Type *FieldTy = ConvertType(FieldType);
         unsigned BitAlignment = Info->getTypeAlignment(FieldTy)*8;
 
         FieldOffsetInBits &= ~(BitAlignment-1ULL);
@@ -2141,10 +2141,9 @@
           continue;
       }
 
-      // Figure out if this field is zero bits wide, e.g. {} or [0 x int].  Do
-      // not include variable sized fields here.
-      bool isZeroSizeField = !TYPE_SIZE(FieldType) ||
-        integer_zerop(TYPE_SIZE(FieldType));
+      // Figure out if this field is zero bits wide, e.g. {} or [0 x int].
+      bool isZeroSizeField = FieldTy->isSized() &&
+        getTargetData().getTypeSizeInBits(FieldTy) == 0;
 
       unsigned FieldNo =
         Info->getLLVMFieldFor(FieldOffsetInBits, CurFieldNo, isZeroSizeField);





More information about the llvm-commits mailing list