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
On Wed, Jan 21, 2009 at 3:12 PM, Bill Wendling <isanbard at gmail.com> wrote:> 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.What's wrong? It is all zeros. If some particular user requires it to be in a special section, it should be marked as such; we shouldn't be guaranteeing a different representation for two constructs which fundamentally represent the same thing. That said, I don't think allowing it would break anything... -Eli
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
Apparently Analagous Threads
- [LLVMdev] How to force the creation of arrays with zeroes?
- [LLVMdev] Fwd: How to force the creation of arrays with zeroes?
- [LLVMdev] How to force the creation of arrays with zeroes?
- [LLVMdev] Fwd: How to force the creation of arrays with zeroes?
- [LLVMdev] Fwd: How to force the creation of arrays with zeroes?