[LLVMbugs] [Bug 931] NEW: ConvertStructFieldInitializerToType problems

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Oct 2 14:27:32 PDT 2006


http://llvm.org/bugs/show_bug.cgi?id=931

           Summary: ConvertStructFieldInitializerToType problems
           Product: tools
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: llvm-gcc
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: alenhar2 at uiuc.edu


When compiling the linux kernel (x86), I've hit the assertion in
ConvertStructFieldInitializerToType.
I am seeing several unhandled cases:
a) ConstantExpr initializing UByte arrays.  These happen to be constant GEP
expressions. ([ulong*] -> [4 x ubyte])
b) ConstantPointerNull initializing UByte arrays. ([null] -> [4 x ubyte])
c) arrays of ints intializing arrays of UBytes. ([2049 x uint] -> [8196 x ubyte])
([initializer type] -> [field type])

The following patch was made to solve a and b before c was discovered.  Probably
in light of c, some generalization and simplification should happen.

--- gcc/llvm-convert.cpp        (revision 178)
+++ gcc/llvm-convert.cpp        (working copy)
@@ -4488,9 +4488,9 @@
  // If this is an integer initializer for an array of ubytes, we are
  // initializing an unaligned integer field.  Break the integer initializer up
  // into pieces.
-  if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
-    if (const ArrayType *ATy = dyn_cast<ArrayType>(FieldTy))
-      if (ATy->getElementType() == Type::UByteTy) {
+  if (const ArrayType *ATy = dyn_cast<ArrayType>(FieldTy))
+    if (ATy->getElementType() == Type::UByteTy) {
+      if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
        std::vector<Constant*> ArrayElts;
        uint64_t Val = CI->getRawValue();
        for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
@@ -4504,14 +4504,54 @@

          ArrayElts.push_back(ConstantUInt::get(Type::UByteTy, EltVal));
        }
-
        return ConstantArray::get(ATy, ArrayElts);
+      } else if (isa<ConstantPointerNull>(Val)) {
+        std::vector<Constant*> ArrayElts;
+        for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
+          ArrayElts.push_back(ConstantUInt::get(Type::UByteTy, 0));
+        return ConstantArray::get(ATy, ArrayElts);
+      } else if (ConstantExpr* CE = dyn_cast<ConstantExpr>(Val)) {
+        Type* tcasted = 0;
+        switch (TD.getTypeSize(CE->getType())) {
+        case 1: tcasted = Type::UByteTy;  break;
+        case 2: tcasted = Type::UShortTy; break;
+        case 4: tcasted = Type::UIntTy;   break;
+        case 8: tcasted = Type::ULongTy;  break;
+        default: break;
+        }
+        if (tcasted) {
+          std::vector<Constant*> ArrayElts;
+          Constant* CEC = ConstantExpr::getCast(CE, tcasted);
+          for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
+            Constant* EltVal;
+            if (TD.isLittleEndian())
+              EltVal = ConstantInt::get(Type::UByteTy,i);
+            else
+              EltVal = ConstantInt::get(Type::UByteTy,e-i-1);
+            EltVal = ConstantExpr::getCast(
+                       ConstantExpr::getShr(CEC,
+
ConstantExpr::getMul(ConstantInt::get(Type::UByteTy,8),
+                                              EltVal)),
+                       Type::UByteTy);
+            ArrayElts.push_back(EltVal);
+          }
+          return ConstantArray::get(ATy, ArrayElts);
+        }
      }
-  }
+    }



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the llvm-bugs mailing list