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

Chris Lattner clattner at apple.com
Wed Jan 21 15:54:50 PST 2009


On Jan 21, 2009, at 3:12 PM, Bill Wendling wrote:

> 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"?

Bill and I spoke about this.  Using CAZ to represent an all-zeros  
array is a fine thing for the LLVM IR to do, and we should continue  
it.  If ObjC needs its string in a special place (not cstring) then  
the front-end should put the right section info on the globalvariable.

-Chris



More information about the llvm-dev mailing list