James Courtier-Dutton via llvm-dev
2020-Nov-11 23:57 UTC
[llvm-dev] 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 << ']'; -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201111/a75e4b34/attachment.html>
Tim Northover via llvm-dev
2020-Nov-12 09:28 UTC
[llvm-dev] Question about LLVM Rel10 llvm/IR/AsmWriter.cpp
On Wed, 11 Nov 2020 at 23:58, James Courtier-Dutton via llvm-dev <llvm-dev at lists.llvm.org> wrote:> 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.
Reasonably Related Threads
- [Update][RFC] Refactor class hierarchy of VectorType in the IR
- [Update][RFC] Refactor class hierarchy of VectorType in the IR
- [RFC] Refactor class hierarchy of VectorType in the IR
- [LLVMdev] Constant::getAllOnesValue(): expected behaviour or bug?
- [RFC] Refactor class hierarchy of VectorType in the IR