[LLVMdev] RFA: Constant String c"\000"

Bill Wendling isanbard at gmail.com
Wed Jan 21 15:12:30 PST 2009


The Constants.cpp file returns a ConstantAggregateZero object when you
pass it a c"\000" string. Here is the code:

Constant *ConstantArray::get(const ArrayType *Ty,
                             const std::vector<Constant*> &V) {
  // If this is an all-zero array, return a ConstantAggregateZero
object
  if (!V.empty()) {
    Constant *C = V[0];
    if (!C->isNullValue())
      return ArrayConstants->getOrCreate(Ty, V);
    for (unsigned i = 1, e = V.size(); i != e; ++i)
      if (V[i] != C)
        return ArrayConstants->getOrCreate(Ty, V);
  }
  return ConstantAggregateZero::get(Ty);
}

This seems wrong to me, and it's causing a problem in Objective-C,
which requires that an empty string be placed in the .cstring section.

Would it break everything or hurt performance to have a check in here
that if this is a [1 x i8] array where C->isNullValue(), we should
allow it to stay instead of creating the CAZ, which is translated into
a "zeroinitialier"?

-bw



More information about the llvm-dev mailing list