Question about LLVM Rel10 llvm/IR/AsmWriter.cpp

Hi,

See fuller extract below.
I am curious about the for loop.
for (unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {

What happens when CA->getNumElements() is zero ? Infinite loop???
Wouldn’t the following be better. i.e. safer:

for (unsigned i = 1; i < CA->getNumElements(); i++) {

Kind Regards

James

At about line 1429:
Type *ETy = CA->getType()->getElementType();
Out << ‘[’;
TypePrinter.print(ETy, Out);
Out << ’ ';
WriteAsOperandInternal(Out, CA->getElementAsConstant(0),
&TypePrinter, Machine,
Context);
for (unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
Out << ", ";
TypePrinter.print(ETy, Out);
Out << ’ ';
WriteAsOperandInternal(Out, CA->getElementAsConstant(i), &TypePrinter,
Machine, Context);
}
Out << ‘]’;

What happens when CA->getNumElements() is zero ? Infinite loop???

It looks like a ConstantArray can't exist with zero elements,
ConstantArray::get produces a ConstantAggregateZero instead. Actually
parsing a .ll file seems to go for UndefValue.

Wouldn't the following be better. i.e. safer:
   for (unsigned i = 1; i < CA->getNumElements(); i++) {

The code above has already dereferenced CA[0] so I think it's no real
improvement.

Cheers.

Tim.